我有一个MKAnnotation
名为arrAnnotations
. 我想挑选一个与存储在CLLocation
名为“newLocation”的对象中的注释具有相同坐标的注释。
我正在尝试使用 a NSPredicate
,但它不起作用。
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(SELF.coordinate == %f)", newLocation.coordinate];
NSArray* filteredArray = [arrAnnotations filteredArrayUsingPredicate:predicate];
[self.mapView selectAnnotation:[filteredArray objectAtIndex:0] animated:YES];
filtersArray 始终包含零个对象。
我也尝试了以下方法,它们也不起作用
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(coordinate == %f)", newLocation.coordinate];
和
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(coordinate > 0)"];
和
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(coordinate.latitude == %f)", newLocation.coordinate.latitude];
最后两个使应用程序崩溃,第三个带有NSInvalidArgumentException
for[NSConcreteValue compare:]
和第四个,因为latitude
不符合键值编码(我认为这是因为坐标只是 ac-struct
而不是NSObject
?)。
我怎样才能使这个工作NSPredicate
?谁能给我一个文档链接,该文档显示谓词如何在幕后工作?尽管我已经阅读并理解了 Apple 的Predicate Programming Guide的大部分内容,但我不明白他们实际上在做什么。使用谓词搜索一个巨大的数组是否比使用 for...in 构造循环遍历它更有效?如果是/否,为什么?