【发布时间】:2016-08-03 19:31:21
【问题描述】:
在AppDelegate.h 我创建了以下属性,
@property (strong, nonatomic) NSMutableDictionary *googleUserDetailsDictionary;
在AppDelegate.m,
static NSString *kGoogleDetails = @"googleDetails";
@synthesize googleUserDetailsDictionary;
我在AppDelegate.m 中创建了一个自定义方法,在其中添加了以下行:
[self setValue:googleUserDetailsDictionary forKey:kGoogleDetails];
在我想成为googleUserDetailsDictionary属性观察者的ViewController中,
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.'
【问题讨论】:
标签: ios objective-c appdelegate key-value-coding