You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CHANGELOG.md
+41Lines changed: 41 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -5,6 +5,46 @@ _**Note:** This is in reverse chronological order, so newer entries are added to
5
5
6
6
## Swift 5.8
7
7
8
+
*[SE-0365][]:
9
+
10
+
Implicit `self` is now permitted for `weak self` captures, after `self` is unwrapped.
11
+
12
+
For example, the usage of implicit `self` below is now permitted:
13
+
14
+
```swift
15
+
classViewController {
16
+
let button: Button
17
+
18
+
funcsetup() {
19
+
button.tapHandler= { [weakself] in
20
+
guardletselfelse { return }
21
+
dismiss() // refers to `self.dismiss()`
22
+
}
23
+
}
24
+
25
+
funcdismiss() { ... }
26
+
}
27
+
```
28
+
29
+
In Swift 5 language modes, implicit `self` is permitted for `weak self` captures in _non-escaping_ closures even before `self` is unwrapped. For example, this code compiles successfully in Swift 5 language modes:
30
+
31
+
```swift
32
+
classExampleClass {
33
+
funcmakeArray() -> [String] {
34
+
// `Array.map` takes a non-escaping closure:
35
+
["foo", "bar", "baaz"].map { [weakself] string in
36
+
double(string) // implicitly refers to `self!.double(string)`
37
+
}
38
+
}
39
+
40
+
funcdouble(_string: String) ->String {
41
+
string + string
42
+
}
43
+
}
44
+
```
45
+
46
+
Starting in Swift 6, the above code will no longer compile. `weak self` captures in non-escaping closures will have the same behavior as captures in escaping closures (as described in [SE-0365][]). Code relying on the previous behavior will need to be updated to either unwrap `self` (e.g. by adding a `guard let self else return` statement), or to use a different capture method (e.g. using `[self]` or `[unowned self]` instead of `[weak self]`).
47
+
8
48
*[SE-0362][]:
9
49
10
50
The compiler flag `-enable-upcoming-feature X` can now be used to enable a specific feature `X` that has been accepted by the evolution process, but whose introduction into the language is waiting for the next major version (e.g., version 6). The `X` is specified by any proposal that falls into this category:
0 commit comments