我有一個對象數組。在這個對象上是一個NSDecimalNumber屬性distanceFromDevice。訂單數組升序
我想要通過此屬性來訂購此數組。我一直在努力排序幾個小時,任何人有任何建議?
- (void)buildSearchableListUsing:(CLLocation *)newLocation
{
listContent = [[NSMutableArray alloc] init];
for(NSAirport *regionalAirport in airportsList)
{
CLLocation *location = [[CLLocation alloc]initWithLatitude:[regionalAirport.latitude doubleValue] longitude:[regionalAirport.longitude doubleValue]];
regionalAirport.distanceFromDevice = [[NSDecimalNumber alloc]initWithDouble:[newLocation distanceFromLocation:location]];
NSLog(@"distanceFromDevice %@", regionalAirport.distanceFromDevice);
[listContent addObject:regionalAirport];
}
//I want listContent ordered by the property distanceFromDevice
}
見http://stackoverflow.com/questions/805547/ how-to-sort-an-nsmutablearray -with-custom-objects-in-it – AlcubierreDrive 2010-11-01 09:31:38