Skip to content

Commit a2f742b

Browse files
committed
wip: Resolving Explicit Redundancy
1 parent 5f65ecf commit a2f742b

File tree

1 file changed

+3
-12
lines changed

1 file changed

+3
-12
lines changed

swift-6-beta.docc/ReferenceManual/Declarations.md

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2340,16 +2340,9 @@ doSomething(with: oneAndTwo)
23402340

23412341
具体类型只能遵从某个协议一次。Swift 会将多余的协议遵从标记为错误。你可能会在两种情况下遇到这种错误。第一种情况是,当你以不同的要求多次显式地遵从同一个协议。第二种情况是,当你多次隐式地继承同一个协议。以下部分将讨论这些情况。
23422342

2343-
#### Resolving Explicit Redundancy
2343+
#### 解决显式冗余
23442344

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` 元素的数组。
23532346

23542347
```swift
23552348
protocol Serializable {
@@ -2399,9 +2392,7 @@ extension Array: Serializable where Element == String {
23992392
```
24002393
-->
24012394

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+
如果您需要根据多个具体类型添加条件遵循,请创建一个每个类型都可以遵循的新协议,并在声明条件遵循时使用该协议作为要求。
24052396

24062397
```swift
24072398
protocol SerializableInArray { }

0 commit comments

Comments
 (0)