错误:
Terminating app due to uncaught exception 'NSUnknownKeyException', reason:
'[<__NSDictionaryI 0x100110e00> valueForUndefinedKey:]:
this class is not key value coding-compliant for the key .'
示例代码:
NSDictionary *dict = @{ @"foo": @"bar" };
NSLog(@"foo=%@, qaz=%@", [dict valueForKey:@"foo"], [dict valueForKey:@"qaz"]);
NSLog(@"@=%@", [dict valueForKey:@"@"]); // SIGABRT
使用时也会发生这种情况[dict objectForKey:@"@"]
。
即使定义了“@”键,它仍然会导致SIGABRT
:
NSDictionary *dict = @{ @"@": @"at-sign" };
NSLog(@"@=%@", [dict valueForKey:@"@"]); // SIGABRT
为什么会发生这种情况,如何从字典中检索“@”键的值?