I test this out I created a new playground from Xcode 10.1’s macOS > Blank template. And lo! it does crash.
Clicking on the Quick Look button, I see a backtrace that indicates that this isn’t a problem with the timer per se, but rather a problem with the playground’s logging support. So, rather than try to debug that, I thought I’d post a working example:
import Foundation
import PlaygroundSupport
PlaygroundPage.current.needsIndefiniteExecution = true
var bottleCount = 99
let timer = Timer.scheduledTimer(withTimeInterval: 3.0, repeats: true) { _ in
print("\(bottleCount) bottles of beer on the wall")
bottleCount -= 1
}
print("scheduled")
Share and Enjoy
—
Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
let myEmail = "eskimo" + "1" + "@apple.com"