[英]Swift Error “Variable used within its own initial value”
我正在为我的应用程序编写XCUITest。 我声明警报是为了使用waitForExpectationsWithTimeout
使我的测试异步....但是,它在第5行的alert
声明中抛出了错误Variable used within its own initial value
。
let timeout = NSTimeInterval()
let app = XCUIApplication()
let exists = NSPredicate(format: "exists == 1")
let alert = alert.buttons["OK"]
testCase.addUIInterruptionMonitorWithDescription("Enable Notifications") { (alert) -> Bool in
alert.buttons["OK"].tap()
return true
}
self.buttons["Enable notifications"].tap()
testCase.expectationForPredicate(exists, evaluatedWithObject: alert, handler: nil)
testCase.waitForExpectationsWithTimeout(timeout, handler: nil)
app.tap()
有人可以告诉我为什么会引发此错误,以及我可以采取哪些措施来解决此问题。 提前致谢。
这是因为在您的行号。 5,你写了
let alert = alert.buttons["OK"]
在此行之前从未声明过alert,因此您不能编写此代码。
举例来说,
let a = a+5
现在,编译器将抛出相同的错误,因为它不知道之前未声明的'a'值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.