Group Group Group Group Group Group Group Group Group

Problem chapter 2 core data by tutorials

please in the second chapter i can’t manage to pass “managedcontext” from the app delegate
if i use UIapplication.shared in viewdidload it works but if i try using the code below in AppDelegate i receive a nil managedcontext when trying to run my programm

guard let vc =
window?.rootViewController as? ViewController else {

return true


vc.managedContext = persistentContainer.viewContext

best regards

@carlo476 Thanks very much for your question!

The problem is that after setting the managed object context property, you don’t do anything else. What you need to do is put your ViewController inside a NavigationController and then push the new ViewController. In this case, ViewController would be the rootViewController for the UINavigationController.

I hope this helps!

All the best.

but i don’t understand why i need a navigationcontroller, normally i should be able to pass my managedcontext without that just by setting my window and root view controller but i can’t get it to work, is it possible to explain the proper code to share my instance with my view controller ?

thanks a lot in advance

kind regards