Skip to content

Instantly share code, notes, and snippets.

@standinga
Last active July 9, 2019 22:08
Show Gist options
  • Save standinga/ad8e4787c38d6eecfba95d559fe7529d to your computer and use it in GitHub Desktop.
Save standinga/ad8e4787c38d6eecfba95d559fe7529d to your computer and use it in GitHub Desktop.
function parsing into to string after defined delay time
func fetchData(_ data: Int, delay: Double, completionHandler: @escaping (String)->()) {
DispatchQueue.main.asyncAfter(deadline: .now() + delay) {
completionHandler("\(data)")
}
}
var text = ""
for i in 0..<20 {
fetchData(i, delay: Double.random(in: 0...0.2)) {
text += "\($0) - "
}
}
print("text:", text)
RunLoop.current.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment