KVC
直到现在我都用来访问对象的属性。
在我的对象中,我有一个这样的方法:
-(Address *)mainAddress {
if (self.addresses != nil) {
return [self.addresses anyObject]; //stub method
}
else {
return nil;
}
}
我可以使用这种KVC
方法
mystring = [cliente valueForKeyPath:@"mainAddress.city"];
但我不能用来创建NSFetchRequestController
(此代码使用 MagicalRecord)
NSFetchedResultsController *acontroller = [Customer fetchAllSortedBy:@"mainAddress.city" ascending:ascending withPredicate:companyPredicate groupBy:nil delegate:self];
这是错误:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'keypath mainAddress.city not found in entity <NSSQLEntity Customer id=4>'