我希望将我的managedObjectContext
传递给下一个控制器。我在appDelegate文件中创建了一个UIWindow
实例,因为我需要获取我的备用控制器。然而,Xcode说我的UIWindow
实例是空的。
这是我的代码:
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
}
这有点奇怪。如何解决?提前感谢。