- (void)fetchResult
{
NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"Project" ascending:YES];
[request setEntity:self.entityDescription];
[request setSortDescriptors:[NSArray arrayWithObject:sortDescriptor]];
self.fetchResultController = [[NSFetchedResultsController alloc] initWithFetchRequest:request managedObjectContext:self.managedObjectContext sectionNameKeyPath:nil cacheName:nil];
NSError *fetchError = nil;
BOOL success = [self.fetchResultController performFetch:&fetchError];
if (success) {
NSLog(@"fetched!");
}
else {
NSLog(@"fetch fail!");
}
}
的entityDescription和设置在viewDidLoad方法,因为它是如下图所示的背景:核心数据崩溃:的keyPath项目实体未发现
AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
self.managedObjectContext = appDelegate.managedObjectContext;
self.entityDescription = [NSEntityDescription entityForName:@"Project" inManagedObjectContext:self.managedObjectContext];
崩溃信息: *终止应用程序由于未捕获的异常“NSInvalidArgumentException”,原因是:
可能有人送“的keyPath项目实体没有发现”手?;)
非常感谢你的回答;)你做出正确的猜测! – JackieLam 2013-05-02 10:35:19