オブジェクトのNSMutableArrayがあります。以下は構造体です。
//object at index i
locations {
NSString* address;
NSString* state;
NSNumber* distance;
}
NSMutableArrayに上記の構造のような10000個のオブジェクトがあります。場所がNSNumber距離順になるように、この配列をどのように並べ替えますか?
私はこれを試しました:
lowToHigh = [NSSortDescriptor sortDescriptorWithKey:@"distance" ascending:YES];
[locationArray sortUsingDescriptors:[NSArray arrayWithObject:lowToHigh]];
sortDescriptorWithKey:@"distance"
間違って使用していますか?距離は実際にはキーではないため、NSNumber*距離です。
ヘッダー@property (strong, nonatomic)NSNumber* _distance;
を編集してから@synthesize _distance = distance;
メソッドファイルを編集しますが、これはlocationObjects。*オブジェクトクラスにあります。次に、これを現在のクラスにインポートして、この並べ替えを行っています。それは問題ですか?インポート方法はlocationObjects* locObj = [[locationObjects alloc] init];