NSManagedObjectContext - Which of these 2 methods?
Would you modify a view controllers initializer to get the NSManagedObjectContext from the appdelegate?
or would you use this method?
NSMa开发者_如何转开发nagedObjectContext *context = [(MyAppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext];
I normally use the line that you provided and it works perfectly fine.
NSManagedObjectContext *context = [[[UIApplication sharedApplication] delegate] managedObjectContext];
One thing I have found in all of my Cocoa development is that there are many ways to skin a cat. Usually what works best for you is the best way to go about it.
Another way you could do it is to add the NSManagedObjectContext to the NIB and then add outlets to it in all of your other controllers that need a reference to it. That would require a bit of modification to your App Delegate though.
精彩评论