Hello Negm-Awad,

thanks for helping. The idea with the fetch limit and the descending order solves my problem as I am using a SQLite store.

Cheers

Frank

On Oct 7, 2008, at 2:59 PM, Negm-Awad Amin wrote:

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.)

-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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to