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

陌路散爱 提交于 2019-12-08 15:50:40

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/10453448/nsinvalidargumentexception-reason-unknown-predicate-type-for-predicate-bloc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!