I created a NSMutableArray
with two elements; the name of a city (string at index 0) and the distance (double at index 1) from my present position.
for (i=0;i<[City count];++i)
{
distanceFromMe = [Location distanceFromLocation:[cityLocation]];
[a addObject:[cityNames objectatIndex:i]];
[a addObject:@(distanceFromMe)]
[cityArray addObject:a]
}
"Chicago", 560.34
"New York", 204.3456
"Syracuse", 50.04
I would like to sort this array by ascending distances.
"Syracuse", 50.04
"New York", 204.3456
"Chicago", 560.34
I used:
[cityArray sortUsingDescriptors:@[ [NSSortDescriptor sortDescriptorWithKey:nil ascending:YES] ]];
But I keep getting an error of an unrecognized selector sent to instance.
In my reading it appears that the method does not need a key since there is only one NSNumber
in the array element. I've read a number of different threads on this but none seem to apply.
Any help would be appreciated. Using xcode obj-c not swift.