I have several arrays that need to be sorted side by side.
For example, the first array has names: @[@"Joe", @"Anna", @"Michael", @"Kim"], and
and the other array holds addresses: @[@"Hollywood bld", @"Some street 3", @"That other street", @"country road"], where the arrays’ indexes go together. “Joe” lives at “Hollywood bld” and so on.
I would like to sort the names array alphabetically, and then have the address array sorted alongside so they still go together, with “Hollywood bld” having same index as “Joe”. I know how to sort one array alphabetical with
NSSortDescriptor *sort=[NSSortDescriptor sortDescriptorWithKey:@"name" ascending:NO];
[myArray sortUsingDescriptors:[NSArray arrayWithObject:sort]];
But is there any easy way of getting the second array sorted using the appropriate order?
p[i]=inamekey of the first arrayExample: let’s say the first array is
{"quick", "brown", "fox"}. The permutation starts as{0, 1, 2}, and becomes{1, 2, 0}after the sort. Now you can go through the permutation array, and re-order the original array and the second array as needed.