Swift Concurrency 专题
本专题主要解决 Swift 5.5 增加的 Concurrency 功能的学习,首要问题就是要明白Swift Concurrency 是什么。
推荐从官方文档学起,对接口使用能有些概念,接着从提案清单去了解,为什么提出这个功能?解决了什么问题?最终采取的方案为什么是这样做?
最后,可以看看别人对这个功能的理解,以及在实际场景下的实践经验。
1. 官方资料
Concurrency 章节文档:
WWDC 2021 视频:
- Meet async/await in Swift (WWDC21)
- Explore structured concurrency in Swift (WWDC21)
- Swift concurrency: Update a sample app (WWDC21)
- Protect mutable state with Swift actors (WWDC21)
- Swift concurrency: Behind the scenes (WWDC21)
所有相关提案清单如下:
- SE-0296: Async/await 【译】SE-0296 Async/await
- SE-0317: async let
- SE-0300: Continuations for interfacing async tasks with synchronous code 【译】SE-0300 Continuation – 执行同步代码的异步任务接口
- SE-0302: Sendable and @Sendable closures
- SE-0298: Async/Await: Sequences 【译】SE-0298 Async/Await 序列
- SE-0304: Structured concurrency
- SE-0306: Actors 【译】SE-0306 Actors
- SE-0313: Improved control over actor isolation
- SE-0297: Concurrency Interoperability with Objective-C 【译】SE-0297 Concurrency 与 Objective-C 的交互
- SE-0314: AsyncStream and AsyncThrowingStream
- SE-0316: Global actors
- SE-0310: Effectful read-only properties
- SE-0311: Task Local Values
- Custom Executors
2. 闲话 Swift 协程
- 闲话 Swift 协程(0):前言
- 闲话 Swift 协程(1):Swift 协程长什么样?
- 闲话 Swift 协程(2):将回调改写成 async 函数
- 闲话 Swift 协程(3):在程序当中调用异步函数
- 闲话 Swift 协程(4):TaskGroup 与结构化并发
- 闲话 Swift 协程(5):Task 的取消
- 闲话 Swift 协程(6):Actor 和属性隔离
- 闲话 Swift 协程(7):GlobalActor 和异步函数的调度
- 闲话 Swift 协程(8):TaskLocal
- 闲话 Swift 协程(9):异步函数与其他语言的互调用
3. Functional core Imperative shell in Swift. Unidirectional Flow
函数式的核心,命令式的壳,单项数据流。
单项数据流可以看作者的这个系列:
- Redux-like state container in SwiftUI. Basics
- Redux-like state container in SwiftUI. Best practices
- Redux-like state container in SwiftUI. Container Views.
- Redux-like state container in SwiftUI. Connectors.
- Redux-like state container in SwiftUI. Swift concurrency model.
4. Asynchronous programming with SwiftUI and Combine
有了 Combine,还有必要存在 async/await 吗?
5. Async HTTP API clients in Swift
异步 HTTP 请求封装的实践
6. Web API Client in Swift
有了 Async/Await 和 Actors 的特性,现在在 Swift 中设计自定义 Web API 相比以往可以通过少量的抽象,使代码易于理解和扩展,文中进行了一些实践演示应用。
7. Modern Swift Concurrency from Andy Ibanez
作者 Andy Ibanez,来自玻利维亚,10+年 iOS 开发。
本系列文章是作者对 iOS 现代并发的理解。
- Modern Concurrency in Swift: Introduction
- Understanding async/await in Swift
- Converting closure-based code into async/await in Swift
- Structured Concurrency in Swift: Using async let
- Structured Concurrency With Group Tasks in Swift
- Introduction to Unstructured Concurrency in Swift
- Unstructured Concurrency With Detached Tasks in Swift
- Understanding Actors in the New Concurrency Model in Swift
- @MainActor and Global Actors in Swift
- Sharing Data Across Tasks with the @TaskLocal property wrapper in the new Swift Concurrency Model
- Using AsyncSequence in Swift
- Modern Swift Concurrency Summary, Cheatsheet, and Thanks
8. Sundell 关于 Swift Concurrency 的文章合集
作者 Sundell 是一个非常勤快的 Swift 开发人员,经常在个人网站上分享关于 Swift 开发的方方面面,如果了解 Swift 的更多隐藏东西,可以关注他的网站。
9. Hacking With Swift 教程
10. Concurrency by Tutorials
本电子书内容主要包括传统的并发模式,GCD、Operation 等,可以复习一遍来对照 Modern Concurrency 的用法。
11. 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.