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![]
0 commit comments