【发布时间】:2021-11-14 08:58:15
【问题描述】:
我正在尝试获得我的故事板的蓝屏视图,但我对此完全陌生。我不明白如何在课程中导航以进入“蓝屏”,这给了我错误。
最初的想法是通过SceneDelegate中的这个函数来传播变量“managedObjectContext”(CoreData)。
我得到的错误是:条件绑定的初始化程序必须具有 Optional 类型,而不是 '[UIViewController]'
This is my SceneDelegate Error
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
// Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
// If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
// This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
//guard let _ = (scene as? UIWindowScene) else { return }
let mainViewController = window!.rootViewController as! UINavigationController
if let navViewControllers = mainViewController.viewControllers { //error Initializer for conditional binding must have Optional type, not '[UIViewController]'
let controller = navViewControllers.first as! EditViewController
controller.managedObjectContext = managedObjectContext
}
listenForFatalCoreDataNotifications()
return
}
【问题讨论】:
-
错误只是告诉你
if let在这里毫无意义。摆脱它。
标签: ios swift storyboard uiscenedelegate