我正在尝试以一种方式使用NSDictionary
,使得我能够将NSArrays
存储在其中,但是我甚至无法让它对字符串起作用。
_times = [[NSDictionary alloc] init];
NSString *test = @"Test";
[_times setValue:@"testing" forKey:test];
NSLog(@"%@",[_times objectForKey:test]);
对于上面的代码,我收到错误消息:Terminating app due to uncaught exception 'NSUnknownKeyException',reason: '[<__NSDictionaryI 0x8b86540> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key Test。'
为什么NSString *
不能作为键?实际上,这正是该方法要调用的。
setValue:forKeyPath:
时遇到此错误,您应该知道:NSMutableDictionary
),keyPath
访问的那个对象仍然可能是不可变的(NSDictionary
),