Skip to content

Instantly share code, notes, and snippets.

@s4cha
Created May 12, 2017 14:57
Show Gist options
  • Save s4cha/6852ed28e66337ceda04ef7f0cdbb567 to your computer and use it in GitHub Desktop.
Save s4cha/6852ed28e66337ceda04ef7f0cdbb567 to your computer and use it in GitHub Desktop.
AsyncExample.swift
// Say you're on the main thread
DispatchQueue.global(qos: DispatchQoS.QoSClass.background).async {
// Do something expensinve in background
var mySuperLongComputedResult = computeSuperLongStuff()
DispatchQueue.main.async {
// come back to the main thread to ping UI
label.text = mySuperLongComputedResult
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment