Re: predicates and sort descriptors for NSFetchRequest - documentation is a bit vague
Re: predicates and sort descriptors for NSFetchRequest - documentation is a bit vague
- Subject: Re: predicates and sort descriptors for NSFetchRequest - documentation is a bit vague
- From: Keary Suska <email@hidden>
- Date: Wed, 14 Dec 2011 10:32:31 -0700
On Dec 14, 2011, at 9:46 AM, email@hidden wrote:
>
> I have a fetch request with sort descriptors that was sorting on a many-one relationship (i.e., I'm fetching Entity A which has a relationship to one entity B and I was trying to get back the array of A entities sorted on an attribute of B). This doesn't work using sort descriptors; however, if I apply the sort descriptor to the resulting array, it does work.
I will assume you are using a sqlite store--otherwise these issues shouldn't apply…
> The "if you execute a fetch directly, you should typically not add Objective-C-based predicates or sort descriptors to the fetch request." bothers me as I see lots of examples where they are used in books on Core Data.
The key phrase here is "Objective-C-based." I believe the documentation is making a distinction between the full functionality of NSPredicate and NSSortDescriptor as executed in an Objective-C context versus the subset of of this functionality that Core data can translate into a SQL query as described in the doc section "Store Types and Behaviors."
> Can someone please elaborate on what kinds of predicates and sort descriptors you can use when executing an NSFetchRequest using the NSManagedObjectContext method: executeFetchRequest:error: ?
The docs give guidelines, and there is a little more in the Predicate Programming Guide here: http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Predicates/Articles/pBasics.html#//apple_ref/doc/uid/TP40001792-SW3 but generally speaking most predicate syntax is acceptable except for any that use any Cocoa method or Objective-C syntax, such as key paths that don't map directly to the managed object model.
If you find specific situations where predicates don't work that probably should due to these guidelines you should file a radar.
The sort descriptor issue may be how you are specifying the descriptor. It may look at key paths differently, so you may need to experiment with different keys (think SQL rather than KVC).
HTH,
Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"
_______________________________________________
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