@@ -21,6 +21,70 @@ CHANGELOG
21
21
Swift 4.0
22
22
---------
23
23
24
+ * [ SE-0156] [ ]
25
+
26
+ Protocol composition types can now contain one or more class type terms,
27
+ forming a class-constrained protocol composition.
28
+
29
+ For example:
30
+
31
+ ``` swift
32
+ protocol Paintable {
33
+ func paint ()
34
+ }
35
+
36
+ class Canvas {
37
+ var origin: CGPoint
38
+ }
39
+
40
+ class Wall : Canvas , Paintable {
41
+ func paint () { ... }
42
+ }```
43
+
44
+ func render (_ : Canvas & Paintable) { ... }
45
+
46
+ render (Wall ())
47
+ ```
48
+
49
+ Note that class-constrained protocol compositions can be written and
50
+ used in both Swift 3 and Swift 4 mode.
51
+
52
+ Generated headers for Swift APIs will map class-constrained protocol
53
+ compositions to Objective-C protocol-qualified class types in both
54
+ Swift 3 and Swift 4 mode (for instance, `NSSomeClass & SomeProto &
55
+ OtherProto` in Swift becomes ` NSSomeClass <SomeProto, OtherProto>`
56
+ in Objective-C).
57
+
58
+ Objective-C APIs which use protocol-qualified class types differ in
59
+ behavior when imported by a module compiled in Swift 3 mode and
60
+ Swift 4 mode. In Swift 3 mode, these APIs will continue to import as
61
+ protocol compositions without a class constraint
62
+ (eg, ` SomeProto & OtherProto ` ).
63
+
64
+ In Swift 4 mode, protocol-qualified class types import as
65
+ class-constrained protocol compositions, for a more faithful mapping
66
+ of APIs from Objective-C to Swift.
67
+
68
+ Note that the current implementation of class-constrained protocol
69
+ compositions lacks three features outlined in the Swift evolution proposal:
70
+
71
+ - In the evolution proposal, a class-constrained is permitted to contain
72
+ two different classes as long as one is a superclass of the other.
73
+ The current implementation only allows multiple classes to appear in
74
+ the composition if they are identical.
75
+
76
+ - In the evolution proposal, associated type and class inheritance clauses
77
+ are generalized to allow class-constrained protocol compositions. The
78
+ current implementation does not allow this.
79
+
80
+ - In the evolution proposal, protocol inheritance clauses are allowed to
81
+ contain a class, placing a requirement that all conforming types are
82
+ a subclass of the given class. The current implementation does not
83
+ allow this.
84
+
85
+ These missing aspects of the proposal can be introduced in a future
86
+ release without breaking source compatibility with existing code.
87
+
24
88
* [ SE-0142] [ ]
25
89
26
90
Protocols and associated types can now contain ` where ` clauses that
0 commit comments