[swift-users] Initializer accessing self

Ray Fix rayfix at gmail.com
Wed Feb 1 22:23:07 CST 2017


In the working version, I think the timer is first set to nil and then changed to the scheduled timer.  In the non-working case time can only be set exactly once and self access is not legal until after it is set.

Ray


> On Feb 1, 2017, at 8:06 PM, Brandon Knope via swift-users <swift-users at swift.org> wrote:
> 
> 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) {
>         
>     }
> }

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20170201/906e8176/attachment.html>


More information about the swift-users mailing list