@@ -57,6 +57,48 @@ Swift 5.0
57
57
Swift 4.2
58
58
---------
59
59
60
+ * [ SE-0185] [ ]
61
+
62
+ Protocol conformances are now synthesized in extensions in the same file as
63
+ the type definition, allowing automatic synthesis of conditional conformances
64
+ to ` Hashable ` , ` Equatable ` and ` Codable ` (both ` Encodable ` and
65
+ ` Decodable ` ). For instance, if there is a generic wrapper type that can only
66
+ be ` Equatable ` when its wrapped type is also ` Equatable ` , the ` == ` method can
67
+ be automatically constructed by the compiler:
68
+
69
+ ``` swift
70
+ struct Generic <Param > {
71
+ var property: Param
72
+ }
73
+
74
+ extension Generic : Equatable where Param: Equatable {}
75
+ // Automatically synthesized inside the extension:
76
+ // static func ==(lhs: Generic, rhs: Generic) -> Bool {
77
+ // return lhs.property == rhs.property
78
+ // }
79
+ ```
80
+
81
+ Code that wants to be as precise as possible should generally not
82
+ conditionally conform to ` Codable ` directly, but rather its two constituent
83
+ protocols ` Encodable ` and ` Decodable ` , or else one can only (for instance)
84
+ decode a ` Generic<Param> ` if ` Param ` is ` Encodable ` in addition to
85
+ ` Decodable ` , even though ` Encodable ` is likely not required:
86
+
87
+ ``` swift
88
+ // Unnecessarily restrictive:
89
+ extension Generic : Codable where Param: Codable {}
90
+
91
+ // More precise:
92
+ extension Generic : Encodable where Param: Encodable {}
93
+ extension Generic : Decodable where Param: Decodable {}
94
+ ```
95
+
96
+ Finally, due to ` Decodable ` having an ` init ` requirement, it is not possible
97
+ to conform to ` Decodable ` in an extension of a non-final class: such a class
98
+ needs to have any ` init ` s from protocols be ` required ` , which means they need
99
+ to be in the class definition.
100
+
101
+
60
102
* [ SE-0054] [ ]
61
103
62
104
` ImplicitlyUnwrappedOptional<T> ` is now an unavailable typealias of ` Optional<T> ` .
0 commit comments