Objective c 使用NSPredicate访问self.items

Objective c 使用NSPredicate访问self.items,objective-c,ios,core-data,nspredicate,nsfetchedresultscontroller,Objective C,Ios,Core Data,Nspredicate,Nsfetchedresultscontroller,出于各种原因(最后总结),我尝试使用NSFetchedResultsController返回一些nsmanagedObject 具体来说,一个人有许多汽车,使用核心数据关系汽车建模。我想向Person添加另一种方法,以返回与self.cars相同的汽车,但使用FRC 我想我的NSPredicate有一个基本错误,它只用于查找car.person==self: NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] initWithEntity

出于各种原因(最后总结),我尝试使用
NSFetchedResultsController
返回一些
nsmanagedObject

具体来说,一个
有许多
汽车
,使用核心数据关系汽车建模。我想向
Person
添加另一种方法,以返回与self.cars相同的汽车,但使用FRC

我想我的
NSPredicate
有一个基本错误,它只用于查找
car.person==self

NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] initWithEntityName:@"Car"];
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"dateAdded" ascending:YES];


 NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];
   [fetchRequest setSortDescriptors:sortDescriptors];

   NSPredicate *predicate = [NSPredicate predicateWithFormat:@"person == '%@'", self];
   [fetchRequest setPredicate:predicate];

   NSFetchedResultsController *controller = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest
                                                  managedObjectContext:self.managedObjectContext
                                                  sectionNameKeyPath:nil
                                                  cacheName:nil];
   NSError *error;
   BOOL success = [controller performFetch:&error];
没有任何汽车被归还。我的谓词不正确吗

旁注-为什么不直接使用自助汽车呢?
就像我说的,这是一个实验。我希望能从
NSFetchedResultsController的持久缓存中获益,在您正在获取
“Person”
对象的示例中。也许您想取回
“Car”
对象

 NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] initWithEntityName:@"Car"];

谓词中的单引号是错误的,应该是

[NSPredicate predicateWithFormat:@"person == %@", self];

对不起,这是示例中的一个错误-我已经更正了它。谢谢。试着删除谓词中的单引号。成功了。想补充一个答案吗?