• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Sorting a to-many relationship property
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >Sorting a to-many relationship property (From: Rick Mann <email@hidden>)
 >Re: Sorting a to-many relationship property (From: "I. Savant" <email@hidden>)

  • Prev by Date: Re: Redrawing CALayer subclass when super layer is scaled
  • Next by Date: notification when app is moved
  • Previous by thread: Re: Sorting a to-many relationship property
  • Next by thread: Re: Sorting a to-many relationship property
  • Index(es):
    • Date
    • Thread