当我打电话
UIApplication.shared.keyWindow
要尝试在我的测试类中设置根视图控制器,键窗口将返回nil。为什么会这样呢?
这是我设置情节提要的方法:
let testBoard = UIStoryboard(name: "TestStoryboard", bundle: Bundle(for: type(of: self)))
let vc = testBoard.instantiateViewController(withIdentifier: "TestController")
UIApplication.shared.keyWindow?.rootViewController = vc
_ = vc.view
vc.viewDidLoad()
Run Code Online (Sandbox Code Playgroud)