From 4dc673e4441fa221fe4c467bdf4cd7210939822b Mon Sep 17 00:00:00 2001 From: VaJoy Lan Date: Fri, 9 Dec 2022 21:43:46 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=90=8C=E6=AD=A5=E5=AE=98=E6=96=B9?= =?UTF-8?q?=E7=9A=84=E9=94=99=E8=AF=AF=E5=8B=98=E6=AD=A3=20(#1212)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: lanbangjue --- source/02_language_guide/28_Concurrency.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/source/02_language_guide/28_Concurrency.md b/source/02_language_guide/28_Concurrency.md index e30a0f7f..21efafb7 100644 --- a/source/02_language_guide/28_Concurrency.md +++ b/source/02_language_guide/28_Concurrency.md @@ -70,9 +70,9 @@ show(photo) ```swift let firstPhoto = await listPhotos(inGallery: "Summer Vacation")[0] -add(firstPhoto toGallery: "Road Trip") +add(firstPhoto, toGallery: "Road Trip") //此时,firstPhoto暂时地同时存在于两个画廊中 -remove(firstPhoto fromGallery: "Summer Vacation") +remove(firstPhoto, fromGallery: "Summer Vacation") ``` 其它代码不能在 `add(_:toGallery:)` 和 `remove(_:fromGallery:)` 两个方法之间运行。在此期间,第一张图片同时存在于两个图库,暂时打破了应用程序的一个不变量。为了更明确地表示这段代码不能加入 `await` 标记,你可以将这段代码重构为一个同步函数: @@ -266,10 +266,10 @@ print(logger.max) // 报错 你可以通过声明其符合 `Sendable` 协议来将某个类型标记为可发送类型。该协议并不包含任何代码要求,但Swift对其做出了强制的语义要求。总之,有三种方法将一个类型声明为可发送类型: -- 该类型为值类型,且其可变状态由其它可发送数据构成——例如具有存储属性的结构体或是具有关联值的枚举。 - -- 该类型不包含任何可变状态,且其不可变状态由其它可发送数据构成——例如只包含只读属性的结构体或类 - +- 该类型为值类型,且其可变状态由其它可发送数据构成——例如具有存储属性的结构体或是具有关联值的枚举。 + +- 该类型不包含任何可变状态,且其不可变状态由其它可发送数据构成——例如只包含只读属性的结构体或类 + - 该类型包含能确保其可变状态安全的代码——例如标记了 `@MainActor` 的类或序列化了对特定线程/队列上其属性的访问的类。 如需了解Swift对Sendable协议的语义要求的详细信息,请访问 [Sendable](https://developer.apple.com/documentation/swift/sendable) 协议参考。