Callback no rápido Playground 3 [duplicado]
Esta pergunta já tem uma resposta aqui:
Como executo retornos de chamada assíncronos no Playground 8 respostasEstou tentando executar esta linha de código no playground, mas obtendo qualquer saída de response.My Code é a seguinte:
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)")
})