Re: Sorting an NSMutableArray
Re: Sorting an NSMutableArray
- Subject: Re: Sorting an NSMutableArray
- From: Ricky Sharp <email@hidden>
- Date: Sat, 20 Dec 2008 06:24:46 -0600
On Dec 20, 2008, at 6:15 AM, Jacob Rhoden wrote:
How do you sort an NSMutableArray, when the difference between the
two objects is determined by information not contained completely
within the objects themselves. ie in Java you can implement a
Comparator that takes two objects to compare then. Is this similar
in Cocoa?
ie in this case I need to apply a mathematical algorithm using
information from each object to determine which one is greater than
the other.
See sortUsingSelector:
What I then personally do is to create a "Sorting" category on
whatever object it is that the collection will contain. For example:
@interface MyObject (Sorting)
- (NSComparisonResult)myCustomCompare:(MyObject*)rhs;
@end
Then, LHS is self and RHS is the param coming in.
___________________________________________________________
Ricky A. Sharp mailto:email@hidden
Instant Interactive(tm) http://www.instantinteractive.com
_______________________________________________
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