Core Data and NSFetchRequest
I've been working through the Core Data tutorials and documentation on
the Apple site, and they've been very useful. However, I'm stuck at
the moment on using NSFetchRequest.
I've used XCode to design a managed object model and and using Cocoa
Bindings I can very easily create lots of arrays of managed objects,
and have managed objects referencing each other.
However, I now want to access the objects created programmatically.
Through the default "many items" interface and bindings, I have
created a set of managed objects of type Task, which save and restore
to/from the persistent store no problem. What I now want to do is
access those objects, and I think I can get a handle on them by
Reading through the NSPersistentDocumentTutorial, it shows how to use
NSFetchRequest, including the following code snippet:
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Department"
fetchResults = [moc executeFetchRequest:fetchRequest error:&fetchError];
but this seems to assume you have previously inserted the object using
When I invoke
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Task"
"+entityForName: could not locate an NSManagedObjectModel"
Do I need to do something to load the managed object model into the
document - even though it seems to already been in use as the bound
interface is working fine.
On May 11, 2005, at 2:28 PM, Marcus Roberts wrote:
> When I invokeEither 'moc' is nil or you've created the managed object context
> NSEntityDescription *entity = [NSEntityDescription
> I get
> "+entityForName: could not locate an NSManagedObjectModel"
without setting up its persistent store coordinator.
On 5/11/05, mmalcolm crawford <mmalc_lists...> wrote:
>> I get
>> "+entityForName: could not locate an NSManagedObjectModel"
> Either 'moc' is nil or you've created the managed object context
> without setting up its persistent store coordinator.
Thank you! 'moc' was nil - I was trying to access the managed object
context too early, as I reference it through the document, and I was
calling it in the window controller constructor, before the contrller
knew what its document was. It just goes to show, check the simple
things first, but I have learnt alot about the managed object model in
the process anyway. Thanks mmalc!