I have created a project where Core Data is included. If I were to retrieve data from another class other than my AppDelegate – where all the needed methods are – how would I do that ? So how do I get the context and the NSManagedObjectModel ? Do I need those, or is there another way round ?
I have tried making a new NSObjectContext object in my new class but then the debugger says it needs the NSManagedObjectModel. I am a newbie and I’d appreciate any help.
Yes, you need the
NSManagedObjectContext. Basically what you have to do is inject the managedobjectmodel in the class where you want to query the database.So in the class where you want to query the database create a property like this:
And then do in your app delegate:
If this view controller does not have a reference within the app delegate then you can do this:
Hope that helps.