predicates and sort descriptors for NSFetchRequest - documentation is a bit vague
predicates and sort descriptors for NSFetchRequest - documentation is a bit vague
- Subject: predicates and sort descriptors for NSFetchRequest - documentation is a bit vague
- From: email@hidden
- Date: Wed, 14 Dec 2011 11:46:39 -0500
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 then read this link:
http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CoreData/Articles/cdFetching.html
which states:
You cannot fetch using a predicate based on transient properties (although you can use transient properties to filter in memory yourself). Moreover, there are some interactions between fetching and the type of store—for details, see “Store Types and Behaviors.” To summarize, though, if you execute a fetch directly, you should typically not add Objective-C-based predicates or sort descriptors to the fetch request. Instead you should apply these to the results of the fetch. If you use an array controller, you may need to subclass NSArrayController so you can have it not pass the sort descriptors to the persistent store and instead do the sorting after your data has been fetched.
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.
I read the Store Types and Behaviors link also <http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CoreData/Articles/cdPersistentStores.html#//apple_ref/doc/uid/TP40002875-SW3>
but that didn't seem to help me understand it much more. I understand the transient property issue, but don't know what predicates and sort descriptors you can use and which ones you cannot. Predicates are more important to me as I'd like to limit the amount of data (and thus limit the amount of memory used) I get back whereas sorting afterwards is not too big an issue.
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: ?
Thanks,
Dave
_______________________________________________
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