2

Hi i am trying to execute this line of code in playground but getting any output of response.My Code is as follow:

func testCallbackEmpty( callback: @escaping  () -> Void) {

        DispatchQueue.main.asyncAfter(deadline: .now() + 5) {
            callback()
        }
    }

    testCallbackEmpty(callback: { () -> Void in
        print("Hey called here")
    })


enum Result {
    case OK, FAILED
}


func mainCallback(callback: @escaping (Result) -> Void) {
    DispatchQueue.main.asyncAfter(deadline: .now() + 5) {
        callback(Result.OK)
    }

}

mainCallback(callback: { result in
    print("Hurray \(result)")
})
silentsudo
  • 6,730
  • 6
  • 39
  • 81

1 Answers1

5

I had to write

import UIKit

import PlaygroundSupport
PlaygroundPage.current.needsIndefiniteExecution = true

at the top of file

This solved.

silentsudo
  • 6,730
  • 6
  • 39
  • 81