开发者

What is the difference between these inheritance checks?

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

  • YES if the receiving class is a subclass of—or identical to—aClass, otherwise NO.

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜