【发布时间】:2012-04-21 16:20:58
【问题描述】:
尝试从 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”
这有什么问题吗?谢谢。
【问题讨论】:
标签: ios cocoa nsdictionary