• 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 - how to retrieve a particular value (not object)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: CoreData - how to retrieve a particular value (not object)


  • Subject: Re: CoreData - how to retrieve a particular value (not object)
  • From: T Reaves <email@hidden>
  • Date: Fri, 27 May 2005 19:22:31 -0400


On May 27, 2005, at 5:32 PM, Rick Ballard wrote:

On May 27, 2005, at 1:44 PM, T Reaves wrote:

If I have object Foo with a variable bar (a string) as an NSManagedObject, is it possible to run a fetch request /query (something) to return a set of all values of bar? Why I want to do this is I want to execute a fetch request to retrieve all instance of Foo where bar == someValue.

While you can't fetch all values of bar, you can certainly fetch all instances of Foo where bar == someValue. This is what the predicate you can set on an NSFetchRequest is for. See <http:// developer.apple.com/documentation/Cocoa/Reference/CoreData_ObjC/ Classes/NSFetchRequest.html> and <http://developer.apple.com/ documentation/Cocoa/Reference/Foundation/ObjC_classic/Classes/ NSPredicate.html>.


So what you want to do is create a fetch request, set its entity to Foo, and set a predicate on it that tests for bar == someValue. Executing this fetch request on a context will return an array of all instances of Foo whose bar == someValue.

Note that you can do this even more easily by creating your fetch request in your data model in Xcode. If you open your data model, select the Foo entity, and add a fetch request, you can use the graphical predicate builder to build the request's predicate. To get that fetch request at runtime so you can tell the context to execute it, you'd invoke -[NSManagedObjectModel fetchRequestFromTemplateWithName:].



I have the fetch request. What I was wanting to do is to call the fetch request once with each unique value of bar, so that I could group them that way for an NSOutlineView.



_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: CoreData - how to retrieve a particular value (not object)
      • From: mmalcolm crawford <email@hidden>
References: 
 >CoreData - how to retrieve a particular value (not object) (From: T Reaves <email@hidden>)
 >Re: CoreData - how to retrieve a particular value (not object) (From: Rick Ballard <email@hidden>)

  • Prev by Date: NSWindow -performClose: / not updating display
  • Next by Date: Re: CoreData - how to retrieve a particular value (not object)
  • Previous by thread: Re: CoreData - how to retrieve a particular value (not object)
  • Next by thread: Re: CoreData - how to retrieve a particular value (not object)
  • Index(es):
    • Date
    • Thread