Futures, Promises, and Reactive Programming

We have already seen a few examples of how Swift makes it possible to handle asynchronous task execution when we introduced Grand Central Dispatch (GCD) and HTTP communication using URLSession in Chapter 3, Diving into Foundation and the Standard Library. As you may recall from that discussion, when dispatching a task to a GCD queue or passing a callback to an HTTP URLSession, we relied on Swift blocks, also known as closures, as a way to specify what our code was meant to do asynchronously. Closures are not the only way for Swift programmers to write asynchronous code and, while extremely powerful, they may lead to code that is hard to read, prone to leaks and memory issues, and hardly maintainable. ...

Get Hands-On Design Patterns with Swift now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.