이것은 하루 종일 나를 괴롭혔습니다.코어 데이터 관계, NSPredicates 및 NSFetchedResultsController
저는 NSPredicate로 좁혀진 이상한 버그가 있습니다. 두 개의 엔티티가 있습니다 : List와 Person. List는 Person이라고 불리는 Person에게 많은 관계가 있고 Person은 List라는 List와 많은 관계가 있습니다.
나는 내 Tableview 컨트롤러에 List 객체를 전달한다. 그런 다음 그 tableview 컨트롤러가 해당 목록 개체에 속한 Person을 표시하도록합니다. 나는 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 컨트롤러, 시뮬레이터가 그냥 중단됩니다. 콘솔이나 아무것도 로그하지 않습니다. 거의 마치 NSFRC를 분류하는 데 걸리는 것과 같습니다.
사용중인 술어에 문제가 있습니까?
원래 게시물을 편집해야합니다. – indragie