2012-12-26

Managed object context in iOS should get passed around not kept in a global object.

I'm baffled why this information is under Core Data Snippets instead of Core Data Programming Guide, but anyway:
When you create a view controller, you pass it the context it should use.... A view controller typically shouldn’t retrieve the context from a global object such as the application delegate....
Thanks to this Stackoverflow question/answer (in a comment on a bad answer).

If you're skilled enough to ignore dogmatic directives of this nature, then good for you, but I'm not (at the time of this writing). I'm logging this entry because I'm sick of over thinking this topic and then researching it repeatedly.

I would like to add that if I have a class that is passed an NSManagedObject, I do not need to also pass in an NSManagedObjectContext because managedObjectContext is a property of every NSManagedObject. In these cases, I simply extract the MOC from the managed object somewhere within the class.

No comments:

Post a Comment