My app uses Core Data, I used the CoreData template when created my project in Xcode, so I already got NSManagedObjectContext object in my AppDelegate file, but Is it good practice to use this context throughout the all app (move it from one viewController to another)?
or maybe it’s better to allocate more for different reasons?
My app uses Core Data, I used the CoreData template when created my project
Share
For most apps I have done I have generally only created a new managedObjectContext if I am going to do work in a background thread.
I tend pass the managedObjectContext from a presenting viewController to the presented viewController by assigning an ivar or if the controller simply won’t work without some CoreData magic I put it in the designated init method.
If I am selecting a row in a table and presenting a new viewController I will just pass along the managedObject that was selected and then if I need the managedObjectContext I can just use
[managedObject managedObjectContext];I don’t like the idea of the singleton as Core Data stuff is already hard enough to isolate for testing without classes breaking the tell don’t ask rule.