• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: CoreData: Fetching object with maximum of property
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Prev by Date: Re: CoreData: Fetching object with maximum of property
  • Next by Date: Re: Universal app fails on PPC.
  • Previous by thread: Re: CoreData: Fetching object with maximum of property
  • Next by thread: Re: Problems with loose ViewController coupling and KVO to-many relationships
  • Index(es):
    • Date
    • Thread