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
Implicit member expressions now support chains of member accesses, making the following valid:
34
+
35
+
```swift
36
+
let milky: UIColor = .white.withAlphaComponent(0.5)
37
+
let milky2: UIColor = .init(named: "white")!.withAlphaComponent(0.5)
38
+
let milkyChance: UIColor?= .init(named: "white")?.withAlphaComponent(0.5)
39
+
```
40
+
41
+
As is the case with the existing implicit member expression syntax, the resulting type of the chain must be the same as the (implicit) base, so it is not well-formed to write:
42
+
43
+
```swift
44
+
let cgMilky: CGColor = .white.withAlphaComponent(0.5).cgColor
45
+
```
46
+
47
+
(Unless, of course, appropriate `white` and `withAlphaComponent` members were defined on `CGColor`.)
48
+
49
+
Members of a "chain" can be properties, method calls, subscript accesses, force unwraps, or optional chaining question marks. Furthermore, the type of each member along the chain is permitted to differ (again, as long as the base of the chain matches the resulting type) meaning the following successfully typechecks:
50
+
51
+
```swift
52
+
structFoo {
53
+
staticvar foo =Foo()
54
+
staticvar bar =Bar()
55
+
56
+
var anotherFoo: Foo { Foo() }
57
+
funcgetFoo() -> Foo { Foo() }
58
+
var optionalFoo: Foo? { Foo() }
59
+
subscript() -> Foo { Foo() }
60
+
}
61
+
62
+
structBar {
63
+
var anotherFoo =Foo()
64
+
}
65
+
66
+
let _: Foo?= .bar.anotherFoo.getFoo().optionalFoo?.optionalFoo![]
67
+
```
68
+
27
69
Swift 5.3
28
70
---------
29
71
72
+
*[SE-0279][] & [SE-0286][]:
73
+
74
+
Trailing closure syntax has been extended to allow additional labeled closures to follow the initial unlabeled closure:
75
+
76
+
```swift
77
+
// Single trailing closure argument
78
+
UIView.animate(withDuration: 0.3) {
79
+
self.view.alpha=0
80
+
}
81
+
// Multiple trailing closure arguments
82
+
UIView.animate(withDuration: 0.3) {
83
+
self.view.alpha=0
84
+
} completion: { _in
85
+
self.view.removeFromSuperview()
86
+
}
87
+
```
88
+
89
+
Additionally, trailing closure arguments now match the appropriate parameter according to a forward-scan rule (as opposed to the previous backward-scan rule):
In the above example, the trailing closure argument matches parameter `first`, whereas pre-Swift-5.3 it would have matched `second`. In order to ease the transition to this new rule, cases in which the forward-scan and backward-scan match a single trailing closure to different parameters, the backward-scan result is preferred and a warning is emitted. This is expected to be upgraded to an error in the next major version of Swift.
100
+
30
101
*[SR-7083][]:
31
102
32
103
Property observers such as `willSet` and `didSet` are now supported on `lazy` properties:
0 commit comments