Swift 4.x
Put this in some file:
func background(work: @escaping () -> ()) {
DispatchQueue.global(qos: .userInitiated).async {
work()
}
}
func main(work: @escaping () -> ()) {
DispatchQueue.main.async {
work()
}
}
and then call it where you need:
background {
//background job
main {
//update UI (or what you need to do in main thread)
}
}