Search code examples
xcodeswiftnstimer

Swift NSTimer Wait Time Error


I'm using this statement:

 timer = NSTimer.scheduledTimerWithTimeInterval(Double((0.01*i+0.01)), target: self, selector: Selector("Move_Loading"), userInfo: nil, repeats: false)

It displays an error for the Double Could not find an overflow for '+' that accepts the supplied arguments. What does that error mean? (I use Double(i+1) and it works perfectly fine.)


Solution

  • You have to put whitespace around binary operators like "+", "-", "/" and "*" in Swift. Swift is pickier about whitespace than C family languages.

    As shown in Leo's answer (voted), the expression should be

    0.01 * Double(i) + 0.01