Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@OscarSwanros
Last active January 3, 2017 18:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OscarSwanros/86b15b273de3fb9e2aa1d9ae0bfef75b to your computer and use it in GitHub Desktop.
Save OscarSwanros/86b15b273de3fb9e2aa1d9ae0bfef75b to your computer and use it in GitHub Desktop.
Execute on main thread
public func p3_executeOnMainThread(handler: (Void) -> Void) {
if Thread.isMainThread {
handler()
} else {
DispatchQueue.main.sync(execute: handler)
}
}
func main() {
p3_executeOnMainThread {
// do some UI stuff
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment