Search code examples
iosswiftswift-playgrounddispatch-queue

Playground - DispatchQueue.main.asyncAfter not working


I am running the following in Playground, but nothing is getting printed :

DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + DispatchTimeInterval.seconds(1)) {
    print("hiii")
}

Solution

  • You can do this, to make it wait for your async thread:

    PlaygroundPage.current.needsIndefiniteExecution = true