You can sort mutable arrays by providing a selector that is invoked on each of the elements of the array. I always get confused about NSOrderedAscending / NSOrderedDescending (I think they're actually backwards, but that's just me). Here it is in a nutcase: Given this sort command:[themStitches sortUsingSelector: @selector(compareByRowLocation:)];And this selector on the BWCrossStitch class:- (NSComparisonResult) compareByRowLocation: (BWCrossStitch *) thing2;Figure out which is lesser or greater, and return one of these. Note thatself
is the object's logical value, not the actual value of theself
pointer.
NSOrderedAsending
ifself
<thing2
NSOrderedDescending
ifself
>thing2
NSOrderedSame
ifself
==thing2