0

I am new to coding (and this website) and I am trying to build a stopwatch using a tutorial off YouTube and I can't get it to work. When I program the function for updating the Timer, the error "% is unavailable: Use truncatingRemainder instead" shows on lines 6 and 7. I'm coding in the latest version of Swift using the latest Xcode version. Could someone please tell me how to get it to work with truncatingRemainder with milliseconds? I really appreciate it.

Here is the link to the tutorial: https://www.youtube.com/watch?v=xp0dvmvh3Cw

 func updateElapsedTimeLabel (timer : Timer)
{
    if watch.isRunning
    {
        let minutes = Int(watch.elapsd/60)
        let seconds = Int(watch.elapsd % 60)
        let ten0fseconds = Int(watch.elapsd * 10 % 10)
        elapsedTimeLabel.text = String (format: "%2d:%2d.%2d", minutes, seconds, ten0fseconds)

    }
    else {
        timer.invalidate()
    }
}
Brandon
  • 23
  • 1
  • 5

1 Answers1

1

just do the following...

let seconds = watch.elapsd.truncatingRemainder(dividingBy: 60)
let ten0fseconds = (watch.elapsd * 10).truncatingRemainder(dividingBy: 10)
pigeon_39
  • 1,503
  • 2
  • 22
  • 34