iOS & Swift

Modern Concurrency in Swift

Learn everything you need to create safe, performant and predictable asynchronous apps by leveraging the new modern concurrency features introduced in Swift 5.5, such as async/await, tasks, actors and more. By Marin Todorov.

Read for Free with the Personal Plan* * Includes this and all other books in our online library See all benefits
Buy Individually $59.99* *Includes access to all of our online reading features.
Leave a rating/review
Download materials
Buy paperback—Amazon Comments
Save for later
Share

Who is this for?

This book is for intermediate Swift developers who are familiar with writing asynchronous applications, but want to leverage the new concurrency features in Swift 5.5 to write safer and more predictable asynchronous apps.

Covered concepts

  • Using async/await
  • Actors
  • Tasks
  • Task Groups
  • Custom Asynchronous Sequences
  • Testing Asynchronous Code
Master Swift’s new concurrency model!

For years, writing powerful and safe concurrent apps with Swift could easily turn into a daunting task, full of race conditions and unexplained crashes hidden in a massive nesting of callback closures.

In Swift 5.5, Apple introduced a new concurrency model featuring the async/await syntax,...

more

Before You Begin

This section tells you a few things you need to know before you get started, such as what you’ll need for hardware and software, where to find the project files for this book, and more.

Section I: Modern Concurrency in Swift

1
Toggle description
Get to know the modern Swift concurrency model, then take a deep dive into async code by working on a real-time stock trading project.
2
Toggle description
Go into more detail about how the async/await syntax and the cooperative asynchronous execution work. Additionally, it introduces the usage of "async let" to design concurrent code and the "Task" type which encapsulates asynchronous execution in the modern concurrency model.
3
Toggle description
Work with async sequences in more detail, proxying Combine to async/await code and managing async tasks.
Create custom asynchronous sequences by leveraging AsyncStream, which lets you wrap existing asynchronous work in your app as an asynchronous sequence without breaking a sweat.
Learn about continuations, which are a way to manually manage suspended functions. You'll use them to bridge between existing non-async/await code and modern, concurrent APIs.
Toggle description
Develop an asynchronous testing infrastructure and learn all the ins-and-outs of testing asynchronous code in the new concurrency model. You'll wrap up by adding unit tests to the Blabber project you worked on in previous chapters.
Toggle description
Create dynamic concurrency with Task Groups, which let you run an arbitrary number of tasks concurrently and offers a natural sequence interface to access and iterate over the results of those tasks.
Toggle description
Actor is the new Swift type that transparently protects its mutable state from data races in a synchronized container, making concurrent programming much safer.
Toggle description
Now that you know actors, you'll learn about a special subset of them — global actors, which allow easy and safe access to shared resources from anywhere in your app.
Toggle description
Create a distributed system that uses actors to execute concurrent tasks on multiple devices over the local network.