これは一日中私を夢中にさせています。
NSPredicate に絞り込んだと思われる奇妙なバグがあります。List と Person の 2 つのエンティティがあります。List は Persons と呼ばれる Person と対多の関係を持ち、Person は Lists と呼ばれる List と対多の関係を持ちます。
テーブルビュー コントローラーに List オブジェクトを渡します。次に、そのテーブルビュー コントローラーに、そのリスト オブジェクトに属する人物を表示させたいと考えています。私は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
テーブルビューコントローラーに渡されると、シミュレーターがハングアップします。コンソールなどにクラッシュログはありません。NSFRC を整理するために AGES を使用しているように見えます。
これは私が使用している述語に問題がありますか?