isMemberOfClass vs comparing classes with ==

2019-05-10 00:40发布

问题:

Is there any real difference between:

id value;
BOOL compare1 = [value isMemberOfClass:[SomeClass class]];
BOOL compare2 = [value class] == [SomeClass class];

to check if value is a SomeClass object?

回答1:

If value is an NSProxy, isMemberOfClass: will properly check the proxied object, the other construct, I believe, won't (I think it will clumsily duplicate isProxy:).