尝试从 NSMutableDictionary 中删除对象后出现异常。相关代码如下。'settings' 被传递给方法并且可以是 NSDictionary 或 NSMutableDictionary。
NSMutableDictionary *mutableSettings = nil;
if ([settings isKindOfClass:[NSMutableDictionary class]])
mutableSettings = (NSMutableDictionary *)settings;
else
mutableSettings = [[[NSMutableDictionary alloc] initWithDictionary:settings] autorelease];
[mutableSettings removeObjectForKey:@"akey"];
这崩溃了
*由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“-[__NSCFDictionary removeObjectForKey:]: mutating method sent to immutable object”
这有什么问题?谢谢。