我已经阅读了有关此崩溃的其他帖子,这与返回 nil 的谓词有关,但我无法用我的应用程序解决这个问题。有人可以帮我吗?
static NSString *const KJMWorkoutCategorySectionKeyPath = @"workoutCategory";
- (NSFetchedResultsController *)fetchedResultsControllerWithSearchString:(NSString *)searchString {
NSManagedObjectContext *sharedContext; // my NSManagedObjectContext instance...
NSFetchRequest *request = [NSFetchRequest new];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Workouts"
inManagedObjectContext:sharedContext];
request.entity = entity;
request.predicate = [NSPredicate predicateWithFormat:@"(workoutName CONTAINS[cd] %@)", searchString];
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:KJMWorkoutCategorySectionKeyPath ascending:YES];
request.sortDescriptors = @[sortDescriptor];
NSFetchedResultsController *fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:request
managedObjectContext:sharedContext
sectionNameKeyPath:KJMWorkoutCategorySectionKeyPath
cacheName:nil];
fetchedResultsController.delegate = self;
NSError *error = nil;
if (![fetchedResultsController performFetch:&error]) {
NSLog(@"Unresolved error %@, %@", error, error.userInfo);
abort();
}
return fetchedResultsController;
}