AppDelegate:此 class 不符合密钥的键值编码 ---

AppDelegate: this class is not key value coding-compliant for the key ---

AppDelegate.h 我创建了以下 属性,

@property (strong, nonatomic) NSMutableDictionary *googleUserDetailsDictionary;

AppDelegate.m

static NSString *kGoogleDetails = @"googleDetails"; @synthesize googleUserDetailsDictionary;

我在 AppDelegate.m 中创建了一个自定义方法,其中添加了以下行: [self setValue:googleUserDetailsDictionary forKey:kGoogleDetails];

在 ViewController 中,我想成为 googleUserDetailsDictionary 属性、

的观察员

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 的 属性。

尝试更改密钥路径以匹配 属性,例如:

static NSString *kGoogleDetails = @"googleUserDetailsDictionary";