Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSInvalidArgumentException', reason: 'Unknown predicate type for predicate: BLOCKPREDICATE(0x70ad750)' Error

I have a core data database and I am trying to create a fetch request using a block predicate, but I get an Unknown Predicate error:

NOTE: employeeToHouse is a property of type House that was created for me when I subclassed NSManagedObject

NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"Place"];
request.predicate       = [NSPredicate predicateWithBlock:^BOOL(id evaluatedObject, NSDictionary *bindings) {
    Place *sortPlace            = (Place *)evaluatedObject;
    CLLocation *placeLocation   = [[CLLocation alloc] initWithLatitude:sortPlace.latitude.doubleValue 
                                                             longitude:sortPlace.longitude.doubleValue];
    CLLocationDistance distance = [placeLocation distanceFromLocation:self.userLocation];
    sortPlace.distanceToUser    = [NSNumber numberWithDouble:distance];
    if(distance<3000)
    {
        return YES;
    }
    return NO;
}];
request.sortDescriptors = [NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@ "distanceToUser" 
                                                                                 ascending:YES 
                                                                                  selector:@selector(localizedCaseInsensitiveCompare:)]];

[self.loadingView removeSpinner];
[self setupFetchedResultsControllerWithFetchRequest:request];

I then get this error:

NSInvalidArgumentException', reason: 'Unknown predicate type for predicate: BLOCKPREDICATE(0x70ad750)'

Am I doing something wrong?

like image 479
Ilya Lapan Avatar asked May 04 '12 17:05

Ilya Lapan


1 Answers

AFAIK you cannot use block predicates with CoreData.

See top voted answer here: NSFetchRequest and predicateWithBlock

The reason being that CoreData cannot translate C-code contained in a block into a SQL query.

like image 171
Cocoanetics Avatar answered Oct 17 '22 12:10

Cocoanetics