Re: sorting a pair of arrays
Re: sorting a pair of arrays
- Subject: Re: sorting a pair of arrays
- From: Mikkel Islay <email@hidden>
- Date: Tue, 28 Jun 2011 15:11:19 +0200
Hi Rick,
It sounds to me like one way of looking at your data structures is as a NSDictionary with the first array as keys and the second as objects (values).
If so, you could then sort the keys using - (NSArray *)keysSortedByValueUsingComparator:(NSComparator)cmptr , or one of the other sorting methods, and use the returned array to access the objects in turn. If the array-contaner is important for your code add the "sorted" objects to an array.
NSArray, of course, also has a set of sorting methods, you could leverage to co-sort the strings in place.
Mikkel
On 28 Jun 2011, at 14:52, Rick C. wrote:
> Hi,
>
> I have a pair of arrays (one of integers and one of strings) and I need to sort the one of integers from largest to smallest and then however it gets sorted I need to copy that sorting in my strings array since they are related. Any advice on what the best way to approach this is would be great since I don't have a lot of experience in sorting like this. Thanks!
>
> rc_______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden