Alex
Alex

Reputation: 3072

Is this an acceptable way of passing ManagedObjectContext?

All of the guides and tutorials that I have read tell me to do it from the app delegate as such:

UINavigationController *navController = (UINavigationController *)self.window.rootViewController;
PictureViewController *picList = (PictureViewController *)[[navController viewControllers] lastObject];
picList.managedObjectContext = self.managedObjectContext;

However, my View Controller is in a crazy hierarchy of container view controllers and navigation view controllers. Is this also an acceptable way of doing it from the target view controller without any nasty consequences?

AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
self.managedObjectContext = appDelegate.managedObjectContext;

Upvotes: 1

Views: 110

Answers (1)

gschandler
gschandler

Reputation: 3208

In short, Yes. Either method is fine. I have seen examples of people just accessing it directly from the delegate, and not save it as an ivar in the view controller. Most cases, and my preference, is to do as you did above.

As long as you are respecting concurrency issues, you will be fine.

Upvotes: 1

Related Questions