コードはiOS5以降で正常に機能します。
NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"FooBar"];
request.sortDescriptors = [NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"ident"
ascending:NO
selector:@selector(compare:)]];
request.predicate = [NSPredicate predicateWithFormat:@"xxx = %@", @"yyy"];
self.fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:request
managedObjectContext:model.managedObjectContext
sectionNameKeyPath:nil
cacheName:nil];
しかし、iOS 4では、次のエラーが発生しました。
'NSObjectInaccessibleException', reason: 'This fetch request (0x70d4700)
was created with a string name (FooBar), and cannot respond to -entity
until used by an NSManagedObjectContext'
2012-11-08 12:12:18.093 hello[1566:11d03] *** Terminating app due to uncaught
exception 'NSObjectInaccessibleException', reason: 'This fetch request
(0x70d4700) was created with a string name (FooBar), and cannot respond
to -entity until used by an NSManagedObjectContext'
*** Call stack at first throw:
(
0 CoreFoundation 0x012405a9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x0104a313 objc_exception_throw + 44
2 CoreData 0x000be68f -[NSFetchRequest entity] + 159
3 CoreData 0x0019f7fb -[NSFetchedResultsController initWithFetchRequest:managedObjectContext:sectionNameKeyPath:cacheName:] + 763
...
このエラーを解決するにはどうすればよいですか?