7 ms·
You can test easily! [array isKindOfClass:[NSMutableArray class]] or [array respondsToSelector:@selector(insertObject:)]
by andrewroycarter 13y ago
You can test easily! [array isKindOfClass:[NSMutableArray class]] or [array respondsToSelector:@selector(insertObject:)]
- rogerbinns 13y agoHave you actually tried it? Because the people who have (me included) found that both tests will return YES, yet when you try a mutable operation you get an exception. http://stackoverflow.com/questions/1788690/objective-c-how-to-check-if-variable-is-nsarray-or-nsmutablearray http://stackoverflow.com/questions/1788690/objective-c-how-t... http://www.cocoabuilder.com/archive/cocoa/224795-nsdictionary-mutability-test.html http://www.cocoabuilder.com/archive/cocoa/224795-nsdictionar...
- blakewatters 13y agoYou cannot use `isKindOfClass:` to introspect an array like this. Most of the toll-free bridged foundation classes such as arrays/dictionaries/sets are implemented as class clusters.