On 07-feb-2011, at 16:29, Ken Thomases wrote:

> On Feb 7, 2011, at 8:56 AM, Michael Crawford wrote:
> 
>> I'm trying to implement a feature where I sort a cross-section of music from 
>> multiple genres with up to two different keys, where the items with a genre 
>> matching the first key appear first in the collection and items with a genre 
>> matching the second key appear after the first group in the collection.  All 
>> songs with a genre not matching the first or second keys can be in any order 
>> following the first two groups.
>> 
>> So I took a look at NSSortDescriptor but it is not apparent to me how I 
>> would accomplish my goal with this class.  If I sort with it based on the 
>> genre key, will basically sort them in alphabetical ascending or descending 
>> order, not what I want.
> 
> Here are two possible approaches:
> 
> 1) Implement a synthetic property which is more amenable to the sort ordering 
> you want.  Something which returns 0 for the first genre, 1 for the second, 
> and 2 for all others, for example.
> 
> 2) Implement a custom comparator method that compares the existing genre 
> property in the manner you want: the first genre equal to itself but coming 
> before all others; the second genre coming after the first, equal to itself, 
> and coming before the remaining genres; all other genres coming after the 
> first two but unordered with respect to each other.
> 
> Either or both of these methods could be implemented in a category if that 
> makes things easier.
> 

Or subclass the NSSortdescriptor and implement

- (NSComparisonResult)compareObject:(id)object1 toObject:(id)object2


Cool Runnings,
Erne.

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to