我想通过使用文件在我的 Swift 项目中使用 Coordinator Navigator()
,但我需要将UINavigationController
内部传递给navigator.show()
.
问题是 XCode 显示此错误:
Fatal Error: Unexpectedly found nil while unwrapping an Optional value in window!
应用委托
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow!
let navigator = Navigator()
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
let feedNavigation = window!.rootViewController! as! UINavigationController
navigator.show(segue: .listBeer, sender: feedNavigation)
return true
}
}
如何将其window.rootViewController! as! UINavigationController
作为非可选值传递?