Re: Objective-C question
Re: Objective-C question
- Subject: Re: Objective-C question
- From: Andy Lee <email@hidden>
- Date: Tue, 10 Feb 2009 12:31:07 -0500
On Feb 10, 2009, at 12:16 PM, Andy Bettis wrote:
I have an id object that I'd like to test to see if it's a certain
class or a subclass of that class. isKindOfClass gives a very
specific test, is there an easy way to test for an object being a
subclass of a class?
See isMemberOfClass:, which is just below isKindOfClass: in the
documentation.
Actually isKindOfClass: is the *less* specific method.
If you want to check whether an object's class is strictly a subclass
of MyClass, and not MyClass itself, you'll have to do something like
if ([myObject isKindOfClass:[MyClass class]] && [myObject class] !
= [MyClass class]) {
NSLog(@"myObject's class is strictly a subclass");
}
(Note the above is typed in Mail off the top of my head.)
Out of curiosity, why do you want to do this? Sometimes (though not
always) testing for class membership is a sign your object model could
be improved.
--Andy
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden