File tree Expand file tree Collapse file tree 1 file changed +3
-12
lines changed
swift-6-beta.docc/ReferenceManual Expand file tree Collapse file tree 1 file changed +3
-12
lines changed Original file line number Diff line number Diff line change @@ -2340,16 +2340,9 @@ doSomething(with: oneAndTwo)
2340
2340
2341
2341
具体类型只能遵从某个协议一次。Swift 会将多余的协议遵从标记为错误。你可能会在两种情况下遇到这种错误。第一种情况是,当你以不同的要求多次显式地遵从同一个协议。第二种情况是,当你多次隐式地继承同一个协议。以下部分将讨论这些情况。
2342
2342
2343
- #### Resolving Explicit Redundancy
2343
+ #### 解决显式冗余
2344
2344
2345
- Multiple extensions on a concrete type
2346
- can't add conformance to the same protocol,
2347
- even if the extensions' requirements are mutually exclusive.
2348
- This restriction is demonstrated in the example below.
2349
- Two extension declarations attempt to add conditional conformance
2350
- to the ` Serializable ` protocol,
2351
- one for arrays with ` Int ` elements,
2352
- and one for arrays with ` String ` elements.
2345
+ 对一个具体类型的多个扩展不能添加对同一协议的遵循,即使这些扩展的要求是互斥的。以下示例展示了这一限制。两个扩展声明试图为 ` Serializable ` 协议添加条件遵循,一个是针对包含 ` Int ` 元素的数组,另一个是针对包含 ` String ` 元素的数组。
2353
2346
2354
2347
``` swift
2355
2348
protocol Serializable {
@@ -2399,9 +2392,7 @@ extension Array: Serializable where Element == String {
2399
2392
```
2400
2393
-->
2401
2394
2402
- If you need to add conditional conformance based on multiple concrete types,
2403
- create a new protocol that each type can conform to
2404
- and use that protocol as the requirement when declaring conditional conformance.
2395
+ 如果您需要根据多个具体类型添加条件遵循,请创建一个每个类型都可以遵循的新协议,并在声明条件遵循时使用该协议作为要求。
2405
2396
2406
2397
``` swift
2407
2398
protocol SerializableInArray { }
You can’t perform that action at this time.
0 commit comments