Re: Core Data Fetches + Transient Properties + NSPredicateEditor = Sadness
Re: Core Data Fetches + Transient Properties + NSPredicateEditor = Sadness
- Subject: Re: Core Data Fetches + Transient Properties + NSPredicateEditor = Sadness
- From: Jerry Krinock <email@hidden>
- Date: Mon, 20 Apr 2009 11:02:57 -0700
On 2009 Apr 20, at 04:50, Jerry Krinock wrote:
Problem solved
But there's an even better way. Upon further study of the Predicate
Programming Guide, I find that there are even more limitations to Core
Data fetches with predicates. The most troubling is that:
"The Core Data SQL store supports only one to-many operation per
query; therefore in any predicate sent to the SQL store, there may be
only one operator (and one instance of that operator) from ALL, ANY,
and IN."
A much better way appears to be to fetch all objects from the store
with no predicate and then use -[NSArray
filteredArrayWithPredicate:]. This takes only one more line of code,
solves all problems, and is supposedly cheaper too:
"If you use the Core Data framework, the array methods provide an
efficient means of filtering an existing array of objects without —-
as a fetch does —- requiring a round trip to a persistent data store."
Furthermore, now since my left-side expressions don't need to be
managed properties I don't need the categories -- I can just add
simple derived-attribute getters to my target object class and
predicate upon the derived attribute directly.
So, I guess the reason why Apple has never noticed that "Core Data
Fetches + Transient Properties + NSPredicateEditor = Sadness" is
because there's a better way to do it.
Makes me wonder why NSFetchRequest even supports a predicate, since
its predicate has all these limitations and is supposedly more
expensive when compared to fetching all objects and then using -
[NSArray filteredArrayWithPredicate:] ? It would have saved me a day
on the learning curve had it not been there for me to hang myself with.
_______________________________________________
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