Home > Software design >  How can I show every second of a timer in the console while the apps runs?
How can I show every second of a timer in the console while the apps runs?

Time:01-11

Our app currently is not timing out at the correct time, so I wanted to display every second of the timer in the console to see what is going on. Any ideas on how to do this. The Timer is part of the Timer class.

CodePudding user response:

let timer =  Timer.scheduledTimer(withTimeInterval: 1, repeats: true) { (timer) in 
    print("Sometext")
}

CodePudding user response:

If you want to see the time each time the timer fires you could adapt Владимир's answer slightly:

let _ =  Timer.scheduledTimer(withTimeInterval: 1, repeats: true) { (timer) in
    print("Timer fired at at \(DateFormatter.localizedString(from:Date(), dateStyle: .none, timeStyle: .medium))")
}
  •  Tags:  
  • Related