【发布时间】:2012-02-06 08:06:11
【问题描述】:
我有
NSMutableDictionary *mutDic;
它加载了来自其他 NSMutableDictionary 的一些值
从我正在尝试更新其值的警报中
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
[self.mutDic setValue:[[alertView textFieldAtIndex:0] text] forKey:@"lname"];
}
但我遇到了这个异常
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[__NSCFDictionary setObject:forKey:]: mutating method sent to immutable object'
我们如何更新字典?
【问题讨论】:
-
崩溃日志显示您的字典不可变。你能告诉我们你是如何分配/初始化字典的吗?
-
如果您的@property 中有
copy,请将其替换为retain或strong。复制总是创建不可变的对象。
标签: iphone xcode4 nsmutabledictionary