在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.'
答案 0 :(得分:1)
我相信它说的是实话。您没有任何名为change
的属性。
尝试更改密钥路径以匹配属性,例如:
sed "s/.*u'longitude': \([^,]\+\).*u'latitude': \([^,]\+\).*/\1 \2/g" a.json