Last active
January 3, 2017 18:23
-
-
Save OscarSwanros/86b15b273de3fb9e2aa1d9ae0bfef75b to your computer and use it in GitHub Desktop.
Execute on main thread
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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