Swift Concurrency 专题

本专题主要解决 Swift 5.5 增加的 Concurrency 功能的学习,首要问题就是要明白Swift Concurrency 是什么

推荐从官方文档学起,对接口使用能有些概念,接着从提案清单去了解,为什么提出这个功能?解决了什么问题?最终采取的方案为什么是这样做?

最后,可以看看别人对这个功能的理解,以及在实际场景下的实践经验。

1. 官方资料

Concurrency 章节文档:

WWDC 2021 视频:

所有相关提案清单如下:

2. 闲话 Swift 协程

3. Functional core Imperative shell in Swift. Unidirectional Flow

函数式的核心,命令式的壳,单项数据流。

单项数据流可以看作者的这个系列:

  1. Redux-like state container in SwiftUI. Basics
  2. Redux-like state container in SwiftUI. Best practices
  3. Redux-like state container in SwiftUI. Container Views.
  4. Redux-like state container in SwiftUI. Connectors.
  5. 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 现代并发的理解。

  1. Modern Concurrency in Swift: Introduction
  2. Understanding async/await in Swift
  3. Converting closure-based code into async/await in Swift
  4. Structured Concurrency in Swift: Using async let
  5. Structured Concurrency With Group Tasks in Swift
  6. Introduction to Unstructured Concurrency in Swift
  7. Unstructured Concurrency With Detached Tasks in Swift
  8. Understanding Actors in the New Concurrency Model in Swift
  9. @MainActor and Global Actors in Swift
  10. Sharing Data Across Tasks with the @TaskLocal property wrapper in the new Swift Concurrency Model
  11. Using AsyncSequence in Swift
  12. 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.

12. Async / Await in Swift

13. 『 Swift 新并发框架 』系列文章

14. 喵神的 Swift 并发初步