我有一个对象数组。在这个对象上是一个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