Modern Concurrency: Getting Started
Learn how to use Swift’s new native model for writing safe, efficient concurrent code. Create safe, performant and predictable asynchronous apps using these Swift concurrency features: async/await Tasks MainActor Asynchronous sequences By Audrey Tam.
Learning path
This is part of the Concurrency in iOS learning path. View path.
Who is this for?
This course 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
- Tasks
- MainActor
- Asynchronous Sequences
Part 1: Asynchronous Code
What is Swift concurrency? Why is it better than GCD? What about Combine? In this course, you’ll learn how to create safe, performant and predictable asynchronous apps using these Swift concurrency features: async/await, Tasks, asynchronous sequences and MainActor.
Explore Task and async/await in a playground.
Learn how to set up the course server, then use async/await and the task
view modifier in the LittleJohn app’s SymbolListView.
Learn how to define async
properties and subscripts and how to iterate over built-in and custom async sequences.
Use AsyncSequence
in the LittleJohn app’s TickerView
.
Learn how to handle the server becoming unavailable during a price update.
Review what you learned in Part 1 and see what’s coming up in Part 2.
Part 2: Asynchronous Sequences
Learn about the app you’ll build in this part of the course and the Swift concurrency tools you’ll use.
Challenge: Reinforce what you learned in Part 1 by implementing the list view in the SuperStorage app. Try not to peek at LittleJohn’s SymbolListView
.
Use async let
to download server status concurrently with the files list.
In a Button
action, call an asynchronous method that updates view properties. Use Task
to call the asynchronous method and move the model’s helper methods to MainActor
.
Challenge: Show/hide a progress view spinner.
Display a progress view while downloading a file in chunks.
Implement your own custom logic to cancel download tasks that you don’t need anymore.
Create an AsyncSequence
from the Combine publisher of Timer
.
Challenge: Download the file chunks in parallel.
Review what you learned in this course and see what’s covered in Modern Concurrency: Beyond the Basics.