Without considering why you have three arrays here is an algorithm to "sort" them together:
- Create a new array the same size as your three arrays filled with integers starting from 0[†].
- "Sort" this new array using
sortedArrayUsingComparator:
passing a block to the comparison.
- Your block will get called with two values from the array, being two integers. Use those integers to index into
dataArray
and compare the values you find there, returning the result as the block result.
After this you will have an array of integers you can use to indirectly index into your three arrays, e.g. something like:
NSArray *sortedIndicies = [arrayOfInts sortedArrayUsingComparator:...];
// first item according to the sort
id firstDate = dateArray[sortedIndicies[0]];
id firstName = nameArray[sortedIndicies[0]];
You can of course use sortedIndicies
to reorder your original 3 arrays if required.
There are other ways to achieve what you require, for example you can "zip" your three arrays into a single array of three items, sort, then "unzip" again. Zip operations are not provided by NSArray
so you need to write them (both are a simple loop).
HTH
[†] You can use a "fake" array for this is you wish, for inspiration see this answer - your implementation could be simpler.