Here's a small test program I wrote:
#import <Foundation/Foundation.h>
int main(int argc, char **argv) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSArray *arr = [NSArray array];
printf("Arr isMemberOfClass NSArray: %d
", [arr isMemberOfClass:[NSArray class]]);
printf("Arr isKindOfClass NSArray: %d
", [arr isKindOfClass:[NSArray class]]);
[pool release];
return 0;
}
And its output:
$ ./ismemberof
Arr isMemberOfClass NSArray: 0
Arr isKindOfClass NSArray: 1
How useful is the -isMemberOfClass:
method in any of the Foundation classes? I understand this might give the desired results for classes which I subclass, but as for Foundation classes -- I find that a result of false for my arr variable is non-intuitive. Is the reason this happens because NSArray is not a concrete class but instead an abstract class, and underneath the hood NSArray is really a concrete instance of NSCFArray?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…