Timer in Xcode Playground

var timer = Timer()


error:

Execution was interrupted, reason: EXC_BAD_ACCESS (code=1, address=0x0).

The process has been left at the point where it was interrupted, use "thread return -x" to return to the state before expression evaluation.







Could anyone help me please!

Replies

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"

Thanks a lot!