Skip to content

Commit 627acb3

Browse files
amartini51ApolloZhuslavapestovxwu
committed
Incorporate tech review
Co-authored-by: Apollo Zhu <zhuzhiyu@apple.com> Co-authored-by: Slava Pestov <spestov@apple.com> Co-authored-by: Xiaodi Wu <xiaodi.wu@gmail.com>
1 parent 84d6372 commit 627acb3

File tree

1 file changed

+36
-22
lines changed

1 file changed

+36
-22
lines changed

TSPL.docc/LanguageGuide/Protocols.md

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -752,11 +752,14 @@ a nonfailable initializer or an implicitly unwrapped failable initializer.
752752
```
753753
-->
754754

755-
## Protocols That Don't Have Requirements
755+
## Protocols That Have Semantic Requirements
756756

757-
All of the example protocols above have some requirements,
757+
All of the example protocols above require some methods or properties,
758758
but a protocol doesn't have to include any requirements.
759-
You can use a protocol to mark types that satisfy *semantic* requirements,
759+
You can also use a protocol to mark types
760+
that satisfy some *semantic* requirements ---
761+
requirements about how values of those types behave
762+
and about operations that they support ---
760763
not just requirements that you express in code.
761764
<!--
762765
Avoiding the term "marker protocol",
@@ -765,25 +768,30 @@ which more specifically refers to @_marker on a protocol.
765768
The Swift standard library defines several protocols
766769
that don't have any required methods or properties:
767770

768-
- [`Copyable`][] for values that can be copied.
769-
- [`Sendable`][] for values that can be shared across concurrency contexts.
770-
- [`BitwiseCopyable`][] for values that con be copied, bit-by-bit.
771+
- [`Sendable`][] for values that can be shared across concurrency domains,
772+
as discussed in <doc:Concurrency#Sendable-Types>.
773+
- [`Copyable`][] for values that Swift can copy
774+
when you pass them to a function,
775+
as discussed in <doc:Declarations#Borrowing-and-Consuming-Parameters>.
776+
- [`BitwiseCopyable`][] for values that can be copied, bit-by-bit.
771777

778+
[`BitwiseCopyable`]: https://developer.apple.com/documentation/swift/bitwisecopyable
772779
[`Copyable`]: https://developer.apple.com/documentation/swift/copyable
773780
[`Sendable`]: https://developer.apple.com/documentation/swift/sendable
774-
[`BitwiseCopyable`]: https://developer.apple.com/documentation/swift/bitwisecopyable
775781

776782
<!--
777783
These link definitions are also used in the section below,
778784
Implicit Conformance to a Protocol.
779785
-->
780786

781-
For more information about the semantic requirements,
782-
see the protocols' documentation.
787+
For information about these protocols' requirements,
788+
see the overview in their documentation.
783789

784-
You use the same syntax as usual to adopt these protocols.
785-
The only difference is that
786-
there's no code to implement the protocol's requirements.
790+
You use the same syntax to adopt these protocols
791+
as you do to adopt other protocols.
792+
The only difference is that you don't include
793+
method or property declarations that implement the protocol's requirements.
794+
For example:
787795

788796
```swift
789797
struct MyStruct: Copyable {
@@ -1423,24 +1431,24 @@ for level in levels.sorted() {
14231431

14241432
## Implicit Conformance to a Protocol
14251433

1426-
Some protocols are so common that you would write them on almost every type.
1434+
Some protocols are so common that you would write them
1435+
almost every time you declare a new type.
14271436
For the following protocols,
14281437
Swift automatically infers the conformance
1429-
when you define a type that implements the protocol's requirements:
1438+
when you define a type that implements the protocol's requirements,
1439+
so you don't have to write them yourself:
14301440

1431-
- `Codable`
1432-
- `Copyable`
1433-
- `Sendable`
1434-
- `BitwiseCopyable`
1441+
- [`Copyable`][]
1442+
- [`Sendable`][]
1443+
- [`BitwiseCopyable`][]
14351444

1436-
[`Codable`]: https://developer.apple.com/documentation/swift/codable
14371445
<!--
1438-
The remaining definitions for the links in this list
1439-
are in the section above, Protocols That Don't Have Requirements.
1446+
The definitions for the links in this list
1447+
are in the section above, Protocols That Have Semantic Requirements.
14401448
-->
14411449

14421450
You can still write the conformance explicitly,
1443-
but it doesn't have any effect.
1451+
but it doesn't change how your code behaves.
14441452
To suppress an implicit conformance,
14451453
write a tilde (`~`) before the protocol name in the conformance list:
14461454

@@ -1507,6 +1515,12 @@ suppresses the implicit conformance to `Sendable`
15071515
and also prevents any extensions elsewhere in your code
15081516
from adding `Sendable` conformance to the type.
15091517

1518+
> Note:
1519+
> In addition to the protocols discussed above,
1520+
> distributed actors implicitly conform to the [`Codable`][] protocol.
1521+
1522+
[`Codable`]: https://developer.apple.com/documentation/swift/codable
1523+
15101524
## Collections of Protocol Types
15111525

15121526
A protocol can be used as the type to be stored in

0 commit comments

Comments
 (0)