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: Steve Steinitz <email@hidden>
- Date: Wed, 8 Oct 2008 00:29:02 +1100
Hi Frank,
You wrote
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?
I haven't done exactly what you want but if you have an object
that has a to many relationship to all the entities over which
you want to search, you can first do this
NSNumber * theMax = [someObject valueForKeyPath: @"email@hiddenbuteYouWantMaxOf"];
Then build a fetchRequest using theMax.
If you don't have such an object, I think you'll have to load at
least faults for all your objects into memory and then do
NSNumber * theMax = [objects valueForKeyPath: @"@max.attributeYouWantMaxOf"];
Then do the fetchRequest. I think I remember reading somewhere
that @max doesn't cause faults to fire.
There is likely a better way but that might get you going
without too much trouble...
Cheers,
Steve
_______________________________________________
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