Re: Need help sorting with NSSortDescriptor and/or/NSPredicate (Core Data)
Re: Need help sorting with NSSortDescriptor and/or/NSPredicate (Core Data)
- Subject: Re: Need help sorting with NSSortDescriptor and/or/NSPredicate (Core Data)
- From: Ken Thomases <email@hidden>
- Date: Mon, 7 Feb 2011 09:29:49 -0600
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.
Regards,
Ken
_______________________________________________
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