UIApplication BackgroundTasks Through The Lens of Closures

1 - The sync closure func processTwoNumbers(_ num1: Int, _ num2: Int, handler: (Int, Int) -> ()) { handler(num1, num2) } processTwoNumbers(10, 22, handler: { num1, num2 in print(num1 + num2) }) In the above, the handler is called in a sync matter. Same as below (1...100).forEach { val in print(val) } print(101) Uniqueness: The block passed in is executed immediately at the call site. 2 - The async closure β€” block isn’t stored. enum Result { case success(Data?) case failure(Error?) } func startFlow(handler: @escaping (Result) -> ()) { let url = URL(string: "https://i.imgur.com/7oZTmIC.jpeg")! let task = URLSession.shared.dataTask(with: url) { data, response, error in if error == nil { handler(.success(data)) } else { handler(.failure(error)) } } task.resume() } Uniqueness: handler block is called by the startFlow function. Execution of the block is within the function itself. It gets called after some asynchronous operation. ...