NSInvalidArgumentException',reason:'谓词的未知谓词类型:BLOCKPREDICATE(0x70ad750)'错误 [英] 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:
注意:employeeToHouse是属于House类型的属性,当我将NSManagedObject子类化时,为我创建了
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];
我得到这个错误:
NSInvalidArgumentException',原因:'
谓词的未知谓词类型:BLOCKPREDICATE(0x70ad750)'
NSInvalidArgumentException', reason: 'Unknown predicate type for predicate: BLOCKPREDICATE(0x70ad750)'
推荐答案
AFAIK不能使用CoreData的块谓词。
AFAIK you cannot use block predicates with CoreData.
请参阅顶部投票答案: NSFetchRequest和predicateWithBlock
See top voted answer here: NSFetchRequest and predicateWithBlock
原因是CoreData无法将包含在块中的C代码转换为SQL查询。
The reason being that CoreData cannot translate C-code contained in a block into a SQL query.
这篇关于NSInvalidArgumentException',reason:'谓词的未知谓词类型:BLOCKPREDICATE(0x70ad750)'错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!