在AppDelegate.h
我创建了以下属性,
@property (strong, nonatomic) NSMutableDictionary *googleUserDetailsDictionary;
在AppDelegate.m
,
static NSString *kGoogleDetails = @"googleDetails";
@synthesize googleUserDetailsDictionary;
我在 AppDelegate.m
中创建了一个自定义方法我在其中添加了以下行:
[self setValue:googleUserDetailsDictionary forKey:kGoogleDetails];
在我想成为 googleUserDetailsDictionary
的观察者的 ViewController 中属性(property),
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate addObserver:self forKeyPath:@"googleUserDetailsDictionary" options:NSKeyValueObservingOptionOld | NSKeyValueObservingOptionNew context:nil];
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
if ([keyPath isEqualToString:kGoogleDetails]) {
NSLog(@"This is change taking place: %@ \t\t", change);
}
}
然后,当我尝试打开 ViewController
时,出现以下错误:
** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<FIRA_AppDelegate-1470253453284 0x7fd4fa839410> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key googleDetails.'
最佳答案
我相信它告诉你真相。您没有任何名为 googleDetails
的属性。
尝试更改 key 路径以匹配属性,例如:
static NSString *kGoogleDetails = @"googleUserDetailsDictionary";
关于ios - AppDelegate:此类与键的键值编码不兼容---,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38752162/