Timer does not run in Swift 3.0 playground

You need to start a run loop.

RunLoop.main.run(until: Date(timeIntervalSinceNow: 3))

The timer doesn't do anything unless there is a working run loop accepting input. The program simply ends.

Timer reference:

Timers work in conjunction with run loops. [...] it fires only when one of the run loop modes to which the timer has been added is running and able to check if the timer’s firing time has passed.


Your first version works if you allow the Playground to run indefinitely via PlaygroundSupport:

import Foundation
import PlaygroundSupport

PlaygroundPage.current.needsIndefiniteExecution = true 

let timer = Timer.scheduledTimer(withTimeInterval: 3, repeats: true) { timer in
  print("Timer Fired at: \(timer.fireDate)")
}

Adding a run loop manually also works, and might be needed sometimes, but in your case this simple instruction is enough to make the Timer work properly.