I have two arrays, both full of NSString objects like this:
NSMutableArray *titles = [[NSMutableArray alloc] initWithObjects:@"Title1", @"Title2", @"Title3", @"Title4", @"Title5", nil];
NSMutableArray *distances = [[NSMutableArray alloc] initWithObjects:@"139.45", @"23.78", @"347.82", @"10.29", @"8.29", nil];
How can I sort both arrays by the nearest distance first?
So the results would be like this:
titles = @"Title5", @"Title4", @"Title2", @"Title1", @"Title3"
distances = @"8.29", @"10.29", @"23.78", @"139.45", @"347.82"
I understand that NSSortDescriptor can be used in these circumstances but after looking through the documentation, I am still unsure about how.
I would sort the distances this way…
I can’t think of a particularly quick way to get the associated titles sorted, but this should work …