In this post I would like to compare different styles of writing asynchronous code in Swift. Most of it also apply to Objective-C and other languages (like Java or C#) because concepts between platforms are shared very often. Main difference would be syntax and libraries used.
If you want to skip the basics jump to Promises section.
Let’s assume we are in common scenario where we have to download some data from a service and process it. Seems like an easy task, right? One could just write it like this:
let downloadedData = try! Data(contentsOf: url)
let image = UIImage(data: downloadedData)!
let processedImage = process(image)
// voilá! …