I am at a loss:
Why does this not work:
class Test {
let timer: Timer!
init() {
timer = Timer.scheduledTimer(timeInterval: 20, target: self, selector: #selector(test(_:)), userInfo: nil, repeats: true)
}
@objc func test(_ timer: Timer) {
}
}
error: constant 'self.timer' used before being initialized
timer = Timer.scheduledTimer(timeInterval: 20, target: self, selector: #selector(test(_:)), userInfo: nil, repeats: true)
But this does:
class TestTwo {
var timer: Timer!
init() {
timer = Timer.scheduledTimer(timeInterval: 20, target: self, selector: #selector(test(_:)), userInfo: nil, repeats: true)
}
@objc func test(_ timer: Timer) {
}
}