I am trying to passing my managedObjectContext to the next controller.
I innate a UIWindow instance in my appDelegate file, as I need to obtain my stand by controller.
However, Xcode said my UIWindow instance is nil.
This id my code:
lazy var managedObjectContext: NSManagedObjectContext = persistentContainer.viewContext
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
let tabController = window!.rootViewController as! UITabBarController
if let tabViewControllers = tabController.viewControllers {
let navController = tabViewControllers[0] as! UINavigationController
let controller = navController.viewControllers.first as! CurrentLocationViewController
controller.managedObjectContext = managedObjectContext
}
return true
}
It is a bit strange. How to resolve this? Thanks in advance.


