Skip to content

Instantly share code, notes, and snippets.

@AsceticMonk
Last active December 16, 2016 20:23
Show Gist options
  • Save AsceticMonk/ead7128cf349ec93035250247396932d to your computer and use it in GitHub Desktop.
Save AsceticMonk/ead7128cf349ec93035250247396932d to your computer and use it in GitHub Desktop.
New Swift 3.0 Dispatch APIs
import Foundation
import PlaygroundSupport
PlaygroundPage.current.needsIndefiniteExecution = true
// Do something on the main queue asynchronously
DispatchQueue.main.async {
print("Update UI")
}
// Do something after 2 seocnds
let someQueue = DispatchQueue(label: "some.example.queue")
let delayTime = DispatchTime.now() + .seconds(2)
someQueue.after(when: delayTime) {
print("Done")
}
// Perform a task concurrently for specified iterations
DispatchQueue.concurrentPerform(iterations: 3) {
print("\($0) time")
}
// Do something synchronously
someQueue.sync {
print("Blocking")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment