小编jah*_*ven的帖子

XCTestCase:UIApplication.shared.keyWindow返回nil

当我打电话

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)

ios xctest swift swift3

5
推荐指数
1
解决办法
2025
查看次数

标签 统计

ios ×1

swift ×1

swift3 ×1

xctest ×1