Skip to content

Instantly share code, notes, and snippets.

@fethica
Created January 31, 2018 17:35
Show Gist options
  • Save fethica/409b3d803a2ad3636555f7ea997011dd to your computer and use it in GitHub Desktop.
Save fethica/409b3d803a2ad3636555f7ea997011dd to your computer and use it in GitHub Desktop.
[Swift] Switch to main thread
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