Re: CoreData: Fetching object with maximum of property
Re: CoreData: Fetching object with maximum of property
- Subject: Re: CoreData: Fetching object with maximum of property
- From: Negm-Awad Amin <email@hidden>
- Date: Tue, 7 Oct 2008 14:59:58 +0200
Am Di,07.10.2008 um 14:04 schrieb Frank Illenberger:
Hi Bill,
I tried using predicates for this but did not succeed.
What would a predicate look like which finds the object of an entity
with the maximum value for a property?
In contrast to Bill I think, that this is not possible with
predicates. Why?
You want to get the maximum value of an attribute. Obviously this task
includes the knowledge of all values stored in that attribute. So if
Core Data should do that, there are two approaches:
a) Reading all attributes and compare it. This is, what you didn't
want to do.
b) Delegate this task to the SQL store.
The second one is the solution. But predicates filters the attributes.
They do not really aggregate them, even there are some aggregates
available. These aggregates filters the source entity by resolving a
relationship, but not by aggregating a min or max value.
*If there is a solution using predicates, I'm highly interested in it.*
However, there is another solution, that should work:
When you have an entity you can fetch the instances of the entity. And
you can sort them by using a sort descriptor. And you can set a fetch
limit. So simply create a fetch request, set the sort descriptor's key
to the attribute and the sort descriptor's order to descending. Set
the fetch limit to 1. Executing this fetch will lead to the instance
with the value for that attribute.
AFAIK this sort descriptors and limits are passed to the sql store. So
the SQL engine will do that work. (Anyway the SQL engine of course has
to read every value.)
Cheers
Frank
On Oct 7, 2008, at 1:08 PM, Bill Dudney wrote:
Hi Frank,
That and a whole lot more;
http://developer.apple.com/documentation/Cocoa/Conceptual/Predicates/predicates.html#/
/apple_ref/doc/uid/TP40001798
Good luck!
-bd-
http://bill.dudney.net/roller/objc
On Oct 7, 2008, at 3:49 AM, Frank Illenberger wrote:
Hi everybody,
does anybody know if CoreData under Leopard offers a way to fetch
the object of an entity which the maximum of a certain property
value, but without having to fetch all objects into memory?
Cheers
Frank
_______________________________________________
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
_______________________________________________
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
Amin Negm-Awad
email@hidden
_______________________________________________
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