这让我整天发疯。
我有一个奇怪的错误,我认为我已经缩小到一个 NSPredicate。我有两个实体:List 和 Person。List 与名为 Person 的 Person 具有一对多关系,而 Person 与名为 lists 的 List 具有一对多关系。
我将一个 List 对象传递给我的 tableview 控制器。然后,我希望该 tableview 控制器显示属于该列表对象的 Persons。我正在使用 NSFetchedResultsController 执行此操作。
设置 NSFRC 时,我有以下代码(为清楚起见,省略了内存管理)。有问题的清单是myList
:
// Create the request and set it's entity
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Person" inManagedObjectContext:managedObjectContext];
[fetchRequest setEntity:entity];
// Create a predicate to get the persons that belong to this list
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(ANY lists == %@)", myList];
// Assign this predicate to the fetch request
[fetchRequest setPredicate:predicate];
// Define some descriptors
NSSortDescriptor *locationDescriptor = [[NSSortDescriptor alloc] initWithKey:@"location" ascending:YES];
NSSortDescriptor *lastNameDescriptor = [[NSSortDescriptor alloc] initWithKey:@"lastName" ascending:YES];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:locationDescriptor, lastNameDescriptor, nil];
[fetchRequest setSortDescriptors:sortDescriptors];
// Create and initialize the fetch results controller.
NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:managedObjectContext sectionNameKeyPath:@"location" cacheName:nil];
self.fetchedResultsController = aFetchedResultsController;
fetchedResultsController.delegate = self;
我认为问题出在这条线(因为如果我删除它就会消失):
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(ANY lists == %@)", myList];
发生的事情是当父视图传递myList
给 tableview 控制器时,模拟器只是挂起。控制台中没有崩溃日志或任何东西。就好像它只需要 AGES 来整理 NSFRC。
这是我使用的谓词的问题吗?