Obtaining the NSManagedObjectContext
Well I was reading the Core Data tutorial for iOS on Apple's website and I don't quite get it.
How do I actually obtain the NSManagedObjectContext
so I can use it to access to my database?
If you need to create a new context, just use alloc/init and then add a persistent store coordinator. This is described in Creating a New Managed Object Context. If you've already created a context in, say, your app delegate or root view controller, then you just need to pass it into your view controller when the controller is created. For example, the app delegate typically creates the root view controller. The app delegate can create the managed object context and then set the context in the controller.
精彩评论