Ily*_*pan 10 iphone predicate core-data objective-c nsfetchrequest
我有一个核心数据库,我正在尝试使用块谓词创建一个获取请求,但是我得到一个未知谓词错误:
注意: employeeToHouse是我在子类化NSManagedObject时为我创建的House类型的属性
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];
Run Code Online (Sandbox Code Playgroud)
然后我得到这个错误:
NSInvalidArgumentException',原因:'谓词的未知谓词类型:BLOCKPREDICATE(0x70ad750)'
难道我做错了什么?
Coc*_*ics 13
AFAIK您不能在CoreData中使用块谓词.
请参阅此处的最高投票答案:NSFetchRequest和predicateWithBlock
原因是CoreData无法将块中包含的C代码转换为SQL查询.
归档时间: |
|
查看次数: |
2875 次 |
最近记录: |