Re: Sorting a to-many relationship property
Re: Sorting a to-many relationship property
- Subject: Re: Sorting a to-many relationship property
- From: Rick Mann <email@hidden>
- Date: Wed, 16 Jul 2008 18:04:00 -0700
On Jul 16, 2008, at 17:51:30, I. Savant wrote:
You'll need to sort them yourself after you get them if you're
directly getting them via -valueForKeyPath: since there's no way to
specify a sort descriptor at that time. NSArray conveniently has a
method for exactly that purpose.
I realized I'm getting back an NSSet* from the property "bars". Since
CoreData doesn't even think of the result set as an ordered
collection, I see why there's no way to set the sort it should always
apply.
I found a way to do it with NSSortDescriptors, but it's hardly
convenient. I have to allocate 4 objects:
----
NSSortDescriptor* sortDesc = [[NSSortDescriptor alloc] initWithKey:
@"designator"
ascending: YES
selector: @selector(localizedCaseInsensitiveCompare:)];
NSArray* bars = [self.bars allObjects];
bars = [bars sortedArrayUsingDescriptors: [NSArray arrayWithObject:
sortDesc]];
----
If I were better at KVO, I'm sure I could cache the sorted result, but
I'm not sure how yet.
--
Rick
_______________________________________________
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