由于各种原因(最后总结),我正在尝试使用 anNSFetchedResultsController返回一些NSManagedObjects.
具体来说,aPerson有很多Cars,使用核心数据关系汽车建模。我想添加另一种方法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];
根本没有汽车被退回。我的谓词不正确吗?
旁注 - 为什么不直接使用 self.cars?
就像我说的,这是一个实验。我希望从NSFetchedResultsController.