【发布时间】:2014-08-17 19:01:53
【问题描述】:
我正在开发一个 iOS 应用。我有一个扩展 NSObject 的类,它定义了 1 个属性
//.h file
@property (nonatomic,retain) NSMutableDictionary *livedata;
//.m file
if(self = [super init]){
self.livedata = [[NSMutableDictionary alloc] init];
[self.livedata setValue:@"myvalue" forUndefinedKey:@"myUndefinedKey"];
}
我收到此错误。 * 由于未捕获的异常“NSUnknownKeyException”而终止应用程序,原因:“[setValue:forUndefinedKey:]:此类与键 myUndefinedKey 的键值编码不兼容。”
我过去曾将 NSMutableDictionary 用于 kvc、kvo。是的,我看到这个类不符合 kvc。
【问题讨论】:
-
你想要
setValue:forKey而不是setValue:forUndefinedKey -
效果很好。非常感谢!
标签: ios objective-c nsmutabledictionary key-value-observing kvc