Version First Edition
Platform iOS 15
Language Swift 5.5
Editor Xcode 13

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, to let you write asynchronous code that reads like synchronous code. But like any new feature, here be dragons! So how will you achieve the much-desired mastery of Modern Swift Concurrency?

Modern Concurrency in Swift is here for the rescue, showcasing everything you need to know about async/await, tasks, actors, and everything in between!

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.

i

iii

iv

vi

Section I: Modern Concurrency in Swift

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.

1

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.

2

Work with async sequences in more detail, proxying Combine to async/await code and managing async tasks.

3

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.

4

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.

5

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.

6

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.

7

Actor is the new Swift type that transparently protects its mutable state from data races in a synchronized container, making concurrent programming much safer.

8

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.

9

Create a distributed system that uses actors to execute concurrent tasks on multiple devices over the local network.

10

Meet the team

Contributors

Who is this book 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.

Concepts covered in this book

  • Using async/await
  • Actors
  • Tasks
  • Task Groups
  • Custom Asynchronous Sequences
  • Testing Asynchronous Code

Version history

First Edition · iOS 15, Swift 5.5, Xcode 13

v1.0 · Nov 3 2021 · Marin Todorov
See book details
Pro

Modern Concurrency in Swift

By Marin Todorov

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.

Read for Free with an Ultimate Pro Subscription* * 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.
See buying options
Hide buying options

All videos. All books.
One low price.

A raywenderlich.com subscription is the best way to learn and master mobile development — plans start at just $19.99/month!

Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.