Created
January 31, 2018 17:35
-
-
Save fethica/409b3d803a2ad3636555f7ea997011dd to your computer and use it in GitHub Desktop.
[Swift] Switch to 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
struct SwitchToMainThread { | |
static func with(_ block: @escaping (() -> ())) { | |
guard !Thread.isMainThread else { block(); return } | |
DispatchQueue.main.async { SwitchToMainThread.with(block) } | |
} | |
} | |
SwitchToMainThread.with { | |
// Do UI stuff | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment