我正在尝试按最近距离(升序)对 CLLocationDistance
值列表进行排序。我首先将值转换为 NSString
对象,以便我可以使用以下排序:
NSArray *sortedArray;
sortedArray = [distances sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
NSString 无法对数值进行排序。
如何按升序设置数值列表?
最佳答案
我想你想要的是 sortedArrayUsingFunction:context:
使用这样的东西:
NSInteger intSort(id num1, id num2, void *context)
{
int v1 = [num1 intValue];
int v2 = [num2 intValue];
if (v1 < v2)
return NSOrderedAscending;
else if (v1 > v2)
return NSOrderedDescending;
else
return NSOrderedSame;
}
// sort things
NSArray *sortedArray; sortedArray = [anArray sortedArrayUsingFunction:intSort context:NULL];
关于iphone - 在 iPhone 上对 double 组或 CLLocationDistance 值进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1422840/