iOS - distinguir um NSDictionary de um NSMutableDictionary?
Tenho o seguinte fragmento de código:
NSString* value = @"value";
NSString* key = @"key";
NSMutableDictionary* foo = [NSMutableDictionary dictionary];
NSDictionary* bar = [NSDictionary dictionary];
NSAssert([bar isKindOfClass: [NSMutableDictionary class]], @""); // passes the assert as both are NSCFDictionary;
NSAssert([bar respondsToSelector: @selector(setValue:forKey:)], @""); // passes the assert because it NSCFDictionary does respond to the selector
[foo setValue:value forKey:key]; // no problem, foo is mutable
[bar setValue:value forKey:key]; // crash
Então, se eu tiver um objeto que sejaNSDictionary
ouNSMutableDictionary
, com exceção de um bloco try (que eu prefiro evitar), como posso saber a diferenç