Share E-Book
Scan to open this page

Scan with your phone to open this page

AuthorDonny Wals

Practical Swift Concurrency: Makethe most out of Concurrency inSwift 5.7 and beyond When Apple showed us Swift Concurrency at WWDC 2021 it didn’t takelong for me to get excited about it. What surprised me was that it didn’ttake long for people to start messaging me (jokingly) “Practical async /await, when?”. I’m sure people knew I would jump on Concurrency soonerrather than later.What I didn’t tell people at the time was that I registered the domain namefor the book pretty much straight away. Looking at my domain registrar’sinfo, I registered the domain for Practical Swift Concurrency on June 9th2021. That means it took me almost two years to get this book finished. Ofcourse, I didn’t start on the book immediately (too much was stillhappening around Swift Concurrency initially) and I took a couple of breaks(becoming a dad seems like a good excuse to pause writing for a while) butstill, it took me a while to finish this book.If it weren’t for some nudging from some of my friends, people in the community, and people that seemed eager to get their hands on this book Iprobably wouldn’t have had the book done yet. This book is very muchwritten for everybody that’s interested in it. It’s for everybody that wants tolearn more about Swift Concurrency without any needless complication. It’sfor everybody that has been waiting for what I have to say about SwiftConcurrency.I’d like to extend a huge thank you to everybody that helped me write thisbook. First and foremost I’d like to thank my wife, Dorien for her endlesspatience with me bouncing around between working, writing, traveling,and being a father. I’d like to thank Oliver, my son, for being the best babyever. I’d be lying if I said I didn’t write a couple of paragraphs here andthere with him sleeping in the carrying bag as I was rocking back and forthto make sure he wouldn’t wake up.And of course, a huge thank you goes out to the people that have helped meproofread and improve the book’s contents and topics. Thomas,…

AI Reading Assistant

Whole-book reading guide from stratified index samples; jump to passages in the text

AI guide
【One-Line Pitch】 A hands-on guide to Swift Concurrency for iOS developers who want to move past Grand Central Dispatch and write async/await code that is correct, testable, and fast. Best for working Swift developers with some GCD background who want practical patterns rather than language-theory depth. 【Book Arc】 - **Opening (~0%–9%)**: Frames the book's purpose and gives a chapter-by-chapter roadmap, from concurrency fundamentals through async/await, tasks, testing, and Instruments profiling. - **Early (~9%–27%)**: Establishes the conceptual baseline — concurrency vs. parallelism, threads vs. cores, and why a single-threaded program blocks while waiting on input. - **Early (~27%–39%)**: Explains how the CPU interleaves work, why atomic operations freeze apps, and how multi-core parallelism plus a separate main thread keeps UI responsive during network calls. - **Middle (~39%–52%)**: Shows the risks of multi-threading (data races on shared arrays) and reviews pre-Concurrency Swift: GCD queues, serial vs. parallel execution, and the thread-explosion problem Swift Concurrency aims to fix. - **Late (~52%–75%)**: Moves into Swift Concurrency proper — async/await syntax, async contexts, writing your own async functions, and tasks as the new unit of concurrency (no thread talk, no thread explosion). - **Ending (~75%–100%)**: Covers migrating existing code, async sequences and the async algorithms package vs. Combine, parallel work with `async let` and task groups, testing async code with XCTest, and debugging/profiling with Instruments. 【Key Takeaways】 - **Concurrency is not parallelism** (Early): Concurrency means the CPU interleaves multiple tasks over time; parallelism means two or more threads run simultaneously on separate cores. This distinction underpins every later chapter. - **The main thread must stay free** (Early): UI rendering and user interaction live on the main thread, so slow work like network calls belongs elsewhere — the book uses a button-tap network fetch to show why. - **Data races are the hidden cost of multi-threading** (Middle): When parallel threads write to shared memory like a matches array, readers can see inconsistent state and memory can corrupt; synchronization is mandatory. - **GCD's thread explosion is a design flaw, not a bug you can fix** (Middle): Dispatch queues can spawn more threads than CPU cores, forcing expensive context switching — a problem Swift Concurrency eliminates by design. - **Tasks are the foundation of Swift Concurrency** (Late): The book stresses that we no longer talk about threads; tasks are the new thread, and thread count is capped at CPU cores. - **Async/await is introduced gradually** (Late): You learn async and throwing-async syntax, async vs. sync contexts, and how to write your own async functions — including ones that never suspend. - **Parallelism scales through structured tools** (Ending): `async let` and task groups let you spawn child tasks that run in parallel, enabling a data fetcher that makes hundreds of network calls at once. - **Testing and profiling are first-class concerns** (Ending): XCTest support for async code, when to fall back to older testing methods, and using Instruments to inspect task states, actor scheduling, and fix real performance issues. 【Reading Tips】 - **Skim Chapter 1 if you already know concurrency vs. parallelism**, but read the data-race section carefully — it sets up the actors chapter later. - **Use Chapter 2 as a GCD refresher, not a deep dive**: the author explicitly says he won't cover all GCD details, only the problems Swift Concurrency solves. - **Deep-read the tasks chapter (Ch. 4)**: it is the conceptual hinge of the book — if you understand tasks, the rest of the concurrency model falls into place. - **Treat the async sequences/Combine chapter as optional** unless you are migrating from Combine or need the async algorithms package. - **Do the Instruments chapter with a real project open**: the sample app with deliberate performance issues is where the debugging lessons stick. 【Coverage Limits】 The excerpts cover the book's preface, chapter overview, and portions of Chapters 1–2 plus brief summaries of later chapters; detailed code examples, actor internals, and full chapter content are not included, so this guide reflects the book's structure and stated goals rather than every technical detail.
Excerpt 1
was rocking back and forthto make sure he wouldn’t wake up.And of course, a huge thank you goes out to the people that have helped meproofread and improve th...
View in text
Excerpt 2
st and to what extent it supports testing asynchronous code. You will learn how you can write asynchronous tests that await your async functions as well as t...
View in text
Excerpt 3
ix that we need to have multiple CPUs, and multiple threads. Understanding multi-threading A thread in computing can be thought of as a single execution cont...
View in text
Excerpt 4
times that’s due to the existing codebase you’re working on. Other times it could be because you’re using existing Apple frameworks that haven’t been rewritt...
View in text
Excerpt 5
e we actually start digging into Swift Concurrency properly. Exploring semaphores and locks When you’re building apps that perform work concurrently, it’s ve...
View in text
Excerpt 6
t you will have to run a local server to make this all work. The code bundle for this book contains a dedicated folder for each chapter and a folder called m...
View in text
Excerpt 7
for us, we probably want to go async outside of SwiftUI too. We can do this by creating our own Task object as follows: Task { let url = URL (string: "h...
View in text
Excerpt 8
You typically won’t go and mark just any function as async . You will usually do this if: Your function has to await other async functions Your function perf...
View in text
Tags
AI categories
Programming LanguageGoBackend
Publisher: Donny Wals
Publish Year: 2023
Language: English
File Format: EPUB
File Size: 11.4 MB