按整数排序数组?

时间:2012-07-03 18:08:49

标签: iphone objective-c

我有一个名为detailTexts的数组,其数据来自浮点数:

CLLocation *location = [[CLLocation alloc] initWithLatitude:dlog longitude:dlig];
**CLLocationDistance meters = [userLocation distanceFromLocation:location];**
**float detailFloat = meters * 1000;**
if (meters < 10000) {
    NSLog(@"%@", detailText);
    [tableData addObject:name];
    **detailText = [NSString stringWithFormat:@"%f", detailFloat];**
    **[detailTexts addObject:detailText];**
}

我如何对数组进行排序以获得最近的位置? (我知道它在mysql中:SORT BY ...)

Xcode 4.3(更新版本),Mac OS X Lion

1 个答案:

答案 0 :(得分:2)

NSArray *sortedArray =
             [detailTexts sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];