- (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!");
}
}
The entityDescription and the context is set in the viewDidLoad method, as it is shown below:
AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
self.managedObjectContext = appDelegate.managedObjectContext;
self.entityDescription = [NSEntityDescription entityForName:@"Project" inManagedObjectContext:self.managedObjectContext];
Crash info: * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'keypath Project not found in entity '
Could anybody give a hand?;)
let predicate = NSPredicate(format: "\(#keyPath(Scene.relatedProject.name)) == '\(projectName)'")
– Mandola