I have seen examples of Objective-C code apparently doing the same/similar checks using different methods. I want to learn what's the difference in these:
isKindOfClass
isMemberOfClass
isSubclassOfClass
Please also mention if there is a check that I have not mentioned here, because I am learning and have a very poor command at things at the moment.
These are both instance methods:
isKindOfClass:
Is the object an instance of a class, or an instance of a subclass of that class?
isMemberOfClass:
Is the object is an instance of a class? (Does not include subclasses).
Whereas the last one is a class method, (e.g. [NSString isSubclassOfClass:[NSObject class]]
).
isSubclassOfClass:
Is a class equal to another class, or a subclass of that class?
There are so many link on google and specially it has been asked on stackoverflow many times, check my added link in comment and,
iPhone SDK difference between isKindOfClass and isMemberOfClass
Try reading their documentation as well, that will help you a lot.
Edited
Lets say you have a class name External
and inside External
class you have a subclass named Internal
. I hope you have idea about class can have a subclass which can access properties of a main class. so by this method you can ask an Internal
class that , Are you a subclass of External class?
[Internal isSubclassOfClass:External]
And return value will be BOOL
More reading is available on documentation website of Apple
http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSObject_Class/Reference/Reference.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With