@@ -6,6 +6,7 @@ CHANGELOG
6
6
7
7
| Contents |
8
8
| :--------------------- |
9
+ | [ Swift Next] ( #swift-next ) |
9
10
| [ Swift 5.1] ( #swift-51 ) |
10
11
| [ Swift 5.0] ( #swift-50 ) |
11
12
| [ Swift 4.2] ( #swift-42 ) |
@@ -22,12 +23,162 @@ CHANGELOG
22
23
23
24
</details >
24
25
26
+ Swift Next
27
+ ----------
28
+
29
+ * [ SR-6118] [ ] :
30
+
31
+ Subscripts can now declare default arguments:
32
+
33
+ ``` swift
34
+ struct Subscriptable {
35
+ subscript (x : Int , y : Int = 0 ) {
36
+ ...
37
+ }
38
+ }
39
+
40
+ let s = Subscriptable ()
41
+ print (s[0 ])
42
+ ```
43
+
44
+ ** Add new entries to the top of this section, not here!**
45
+
25
46
Swift 5.1
26
47
---------
27
48
49
+ * [ SE-0244] [ ] :
50
+
51
+ Functions can now hide their concrete return type by declaring what protocols
52
+ it conforms to instead of specifying the exact return type:
53
+
54
+ ```
55
+ func makeMeACollection() -> some Collection {
56
+ return [1, 2, 3]
57
+ }
58
+ ```
59
+
60
+ Code that calls the function can use the interface of the protocol, but
61
+ does not have visibility into the underlying type.
62
+
63
+ * [ SE-0254] [ ] :
64
+
65
+ Subscripts can now be declared ` static ` or (inside classes) ` class ` .
66
+
67
+ * [ SE-0252] [ ] :
68
+
69
+ The existing ` @dynamicMemberLookup ` attribute has been extended with a
70
+ support for strongly-typed keypath implementations:
71
+
72
+ ``` swift
73
+ @dynamicMemberLookup
74
+ struct Lens <T > {
75
+ let getter: () -> T
76
+ let setter: (T) -> Void
77
+
78
+ var value: T {
79
+ get {
80
+ return getter ()
81
+ }
82
+ set {
83
+ setter (newValue)
84
+ }
85
+ }
86
+
87
+ subscript <U >(dynamicMember keyPath : WritableKeyPath<T, U>) -> Lens<U> {
88
+ return Lens< U> (
89
+ getter : { self .value [keyPath : keyPath] },
90
+ setter : { self .value [keyPath : keyPath] = $0 })
91
+ }
92
+ }
93
+ ```
94
+
95
+ * [ SR-8546] [ ] , [ SR-9043] [ ] :
96
+
97
+ More thorough checking has been implemented for restrictions around
98
+ escaping closures capturing ` inout ` parameters or values of noescape type.
99
+ While most code should not be affected, there are edge cases where
100
+ the Swift 5.0 compiler would accept code violating these restrictions.
101
+ This could result in runtime crashes or silent data corruption.
102
+
103
+ An example of invalid code which was incorrectly accepted by the Swift 5.0
104
+ compiler is an ` @escaping ` closure calling a local function which
105
+ references an ` inout ` parameter from an outer scope:
106
+
107
+ ``` swift
108
+ struct BadCaptureExample {
109
+ var escapingClosure: () -> ()
110
+
111
+ mutating func takesInOut (_ x : inout Int ) {
112
+ func localFunction () {
113
+ x += 1
114
+ }
115
+
116
+ escapingClosure = { localFunction () }
117
+ }
118
+ }
119
+ ```
120
+
121
+ The compiler now correctly diagnoses the above code by pointing out that
122
+ the capture of ` x ` by ` localFunction() ` is invalid, since ` localFunction() `
123
+ is referenced from an ` @escaping ` closure.
124
+
125
+ This also addresses certain cases where the compiler incorrectly diagnosed
126
+ certain code as invalid, when in fact no violation of restrictions had
127
+ taken place. For example,
128
+
129
+ ``` swift
130
+ func takesNoEscape (_ fn : () -> ()) {
131
+ func localFunction () {
132
+ fn ()
133
+ }
134
+
135
+ { localFunction () }()
136
+ }
137
+ ```
138
+
139
+ * [ SR-2672] [ ] :
140
+
141
+ Conversions between tuple types are now fully implemented.
142
+ Previously, the following would diagnose an error:
143
+
144
+ ``` swift
145
+ let values: (Int , Int ) = (10 , 15 )
146
+ let converted: (Int ? , Any ) = values
147
+
148
+ * [SE- 0242 ][]:
149
+
150
+ The memberwise initializer for structures now provide default values for variables that hold default expressions.
151
+
152
+ ```swift
153
+ struct Dog {
154
+ var name = " Generic dog name"
155
+ var age = 0
156
+
157
+ // The synthesized memberwise initializer
158
+ init (name : String = " Generic dog name" , age : Int = 0 )
159
+ }
160
+
161
+ let sparky = Dog (name : " Sparky" ) // Dog(name: "Sparky", age: 0)
162
+ ```
163
+
28
164
* [ SE-0068] [ ] :
29
165
30
- ` Self ` can now be used inside member functions and for function arguments of structs and enums to refer to the containing type.
166
+ It is now possible to use ` Self ` to refer to the innermost nominal
167
+ type inside struct, enum and class declarations. For example, the
168
+ two method declarations inside this struct are equivalent:
169
+
170
+ ``` swift
171
+ struct Box <Value > {
172
+ func transform1 () -> Self { return self }
173
+ func transform2 () -> Box<Value > { return self }
174
+ }
175
+ ```
176
+
177
+ In classes, ` Self ` is the dynamic type of the ` self ` value, as before.
178
+ Existing restrictions on ` Self ` in declaration types still apply;
179
+ that is, ` Self ` can only appear as the return type of a method.
180
+ However, ` Self ` can now be used inside the body of a method
181
+ without limitation.
31
182
32
183
* [ SR-7799] [ ] :
33
184
@@ -46,12 +197,12 @@ Swift 5.1
46
197
}
47
198
```
48
199
49
- * ` weak ` and ` unowned ` variables can now be used inside types that
50
- declare ` Equatable ` or ` Hashable ` conformance.
200
+ * ` weak ` and ` unowned ` stored properties no longer inhibit the
201
+ automatic synthesis of ` Equatable ` or ` Hashable ` conformance.
51
202
52
203
* [ SR-2688] [ ] :
53
204
54
- An ` @autoclosure ` closure can now be a typealias.
205
+ An ` @autoclosure ` parameter can now be declared with a typealias type .
55
206
56
207
``` swift
57
208
class Foo {
@@ -62,10 +213,12 @@ Swift 5.1
62
213
63
214
* [ SR-7601] [ ] :
64
215
65
- Functions marked with ` @objc ` can now return ` Self `
216
+ Methods declared ` @objc ` inside a class can now return ` Self ` :
66
217
67
218
``` swift
68
- @objc func returnDynamicSelf () -> Self { return self }
219
+ class MyClass : NSObject {
220
+ @objc func clone () -> Self { return self }
221
+ }
69
222
```
70
223
71
224
* [ SR-2176] [ ] :
@@ -109,6 +262,8 @@ Swift 5.1
109
262
Swift 5.0
110
263
---------
111
264
265
+ ### 2019-03-25 (Xcode 10.2)
266
+
112
267
* [ SE-0235] [ ] :
113
268
114
269
The standard library now contains a ` Result ` type for manually propagating errors.
@@ -369,8 +524,6 @@ Swift 5.0
369
524
}
370
525
```
371
526
372
- ** Add new entries to the top of this section, not here!**
373
-
374
527
Swift 4.2
375
528
---------
376
529
@@ -7511,7 +7664,11 @@ Swift 1.0
7511
7664
[SE- 0228 ]: < https: // github.com/apple/swift-evolution/blob/master/proposals/0228-fix-expressiblebystringinterpolation.md>
7512
7665
[SE- 0230 ]: < https: // github.com/apple/swift-evolution/blob/master/proposals/0230-flatten-optional-try.md>
7513
7666
[SE- 0235 ]: < https: // github.com/apple/swift-evolution/blob/master/proposals/0235-add-result.md>
7667
+ [SE- 0242 ]: < https: // github.com/apple/swift-evolution/blob/master/proposals/0242-default-values-memberwise.md>
7668
+ [SE- 0244 ]: < https: // github.com/apple/swift-evolution/blob/master/proposals/0244-opaque-result-types.md>
7514
7669
[SE- 0245 ]: < https: // github.com/apple/swift-evolution/blob/master/proposals/0245-array-uninitialized-initializer.md>
7670
+ [SE- 0252 ]: < https: // github.com/apple/swift-evolution/blob/master/proposals/0252-keypath-dynamic-member-lookup.md>
7671
+ [SE- 0254 ]: < https: // github.com/apple/swift-evolution/blob/master/proposals/0254-static-subscripts.md>
7515
7672
7516
7673
[SR- 106 ]: < https: // bugs.swift.org/browse/SR-106>
7517
7674
[SR- 419 ]: < https: // bugs.swift.org/browse/SR-419>
@@ -7525,12 +7682,16 @@ Swift 1.0
7525
7682
[SR- 2388 ]: < https: // bugs.swift.org/browse/SR-2388>
7526
7683
[SR- 2394 ]: < https: // bugs.swift.org/browse/SR-2394>
7527
7684
[SR- 2608 ]: < https: // bugs.swift.org/browse/SR-2608>
7685
+ [SR- 2672 ]: < https: // bugs.swift.org/browse/SR-2672>
7528
7686
[SR- 2688 ]: < https: // bugs.swift.org/browse/SR-2688>
7529
7687
[SR- 4248 ]: < https: // bugs.swift.org/browse/SR-4248>
7530
7688
[SR- 5581 ]: < https: // bugs.swift.org/browse/SR-5581>
7531
7689
[SR- 5719 ]: < https: // bugs.swift.org/browse/SR-5719>
7690
+ [SR- 6118 ]: < https: // bugs.swift.org/browse/SR-6118>
7532
7691
[SR- 7139 ]: < https: // bugs.swift.org/browse/SR-7139>
7533
7692
[SR- 7251 ]: < https: // bugs.swift.org/browse/SR-7251>
7534
7693
[SR- 7601 ]: < https: // bugs.swift.org/browse/SR-7601>
7535
7694
[SR- 7799 ]: < https: // bugs.swift.org/browse/SR-7799>
7536
7695
[SR- 8109 ]: < https: // bugs.swift.org/browse/SR-8109>
7696
+ [SR- 8546 ]: < https: // bugs.swift.org/browse/SR-8546>
7697
+ [SR- 9043 ]: < https: // bugs.swift.org/browse/SR-9043>
0 commit comments