File tree Expand file tree Collapse file tree 1 file changed +6
-6
lines changed Expand file tree Collapse file tree 1 file changed +6
-6
lines changed Original file line number Diff line number Diff line change @@ -70,9 +70,9 @@ show(photo)
70
70
71
71
``` swift
72
72
let firstPhoto = await listPhotos (inGallery : " Summer Vacation" )[0 ]
73
- add (firstPhoto toGallery: " Road Trip" )
73
+ add (firstPhoto, toGallery : " Road Trip" )
74
74
// 此时,firstPhoto暂时地同时存在于两个画廊中
75
- remove (firstPhoto fromGallery: " Summer Vacation" )
75
+ remove (firstPhoto, fromGallery : " Summer Vacation" )
76
76
```
77
77
78
78
其它代码不能在 ` add(_:toGallery:) ` 和 ` remove(_:fromGallery:) ` 两个方法之间运行。在此期间,第一张图片同时存在于两个图库,暂时打破了应用程序的一个不变量。为了更明确地表示这段代码不能加入 ` await ` 标记,你可以将这段代码重构为一个同步函数:
@@ -266,10 +266,10 @@ print(logger.max) // 报错
266
266
267
267
你可以通过声明其符合 ` Sendable ` 协议来将某个类型标记为可发送类型。该协议并不包含任何代码要求,但Swift对其做出了强制的语义要求。总之,有三种方法将一个类型声明为可发送类型:
268
268
269
- - 该类型为值类型,且其可变状态由其它可发送数据构成——例如具有存储属性的结构体或是具有关联值的枚举。
270
-
271
- - 该类型不包含任何可变状态,且其不可变状态由其它可发送数据构成——例如只包含只读属性的结构体或类
272
-
269
+ - 该类型为值类型,且其可变状态由其它可发送数据构成——例如具有存储属性的结构体或是具有关联值的枚举。
270
+
271
+ - 该类型不包含任何可变状态,且其不可变状态由其它可发送数据构成——例如只包含只读属性的结构体或类
272
+
273
273
- 该类型包含能确保其可变状态安全的代码——例如标记了 ` @MainActor ` 的类或序列化了对特定线程/队列上其属性的访问的类。
274
274
275
275
如需了解Swift对Sendable协议的语义要求的详细信息,请访问 [ Sendable] ( https://developer.apple.com/documentation/swift/sendable ) 协议参考。
You can’t perform that action at this time.
0 commit comments