MKAnnotation
と呼ばれるオブジェクトの配列がありますarrAnnotations
。CLLocation
「newLocation」というオブジェクトに格納されているものと同じ座標を持つ注釈の1つを選びたいです。
を使用しようとしていますNSPredicate
が、機能しません。
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(SELF.coordinate == %f)", newLocation.coordinate];
NSArray* filteredArray = [arrAnnotations filteredArrayUsingPredicate:predicate];
[self.mapView selectAnnotation:[filteredArray objectAtIndex:0] animated:YES];
FilteredArrayには常にゼロのオブジェクトが含まれています。
私も次のことを試しましたが、どちらも機能しません
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(coordinate == %f)", newLocation.coordinate];
と
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(coordinate > 0)"];
と
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(coordinate.latitude == %f)", newLocation.coordinate.latitude];
最後の2つはアプリをクラッシュさせ、3つ目はNSInvalidArgumentException
for[NSConcreteValue compare:]
で、4つ目latitude
はキー値コーディングに準拠していないためです(これは座標が単なるac-struct
であり、NSObject
?ではないためだと思います)。
どうすればこれを機能させることができNSPredicate
ますか?述語が内部でどのように機能するかを示すドキュメントへのリンクを誰かに教えてもらえますか?Appleの述語プログラミングガイドのほとんどを読んで理解したにもかかわらず、彼らが実際に何をしているのか理解していません。for ... in構文でループするよりも、述語を使用して巨大な配列を検索する方が効率的ですか?はい/いいえの場合、なぜですか?