Skip to content

Commit eae9b4e

Browse files
committed
Add SE-0365 to CHANGELOG.md
1 parent e4b8a82 commit eae9b4e

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

CHANGELOG.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,46 @@ _**Note:** This is in reverse chronological order, so newer entries are added to
55

66
## Swift 5.8
77

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+
class ViewController {
16+
let button: Button
17+
18+
func setup() {
19+
button.tapHandler = { [weak self] in
20+
guard let self else { return }
21+
dismiss() // refers to `self.dismiss()`
22+
}
23+
}
24+
25+
func dismiss() { ... }
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+
class ExampleClass {
33+
func makeArray() -> [String] {
34+
// `Array.map` takes a non-escaping closure:
35+
["foo", "bar", "baaz"].map { [weak self] string in
36+
double(string) // implicitly refers to `self!.double(string)`
37+
}
38+
}
39+
40+
func double(_ 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+
848
* [SE-0362][]:
949

1050
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:
@@ -9559,6 +9599,7 @@ Swift 1.0
95599599
[SE-0357]: <https://github.com/apple/swift-evolution/blob/main/proposals/0357-regex-string-processing-algorithms.md>
95609600
[SE-0358]: <https://github.com/apple/swift-evolution/blob/main/proposals/0358-primary-associated-types-in-stdlib.md>
95619601
[SE-0362]: <https://github.com/apple/swift-evolution/blob/main/proposals/0362-piecemeal-future-features.md>
9602+
[SE-0365]: <https://github.com/apple/swift-evolution/blob/main/proposals/0365-implicit-self-weak-capture.md>
95629603

95639604
[SR-75]: <https://bugs.swift.org/browse/SR-75>
95649605
[SR-106]: <https://bugs.swift.org/browse/SR-106>

0 commit comments

Comments
 (0)