Skip to content

Commit c3c15e2

Browse files
Merge pull request #59362 from apple/AnthonyLatsis-patch-1
2 parents 7611f3f + 9cd4ebb commit c3c15e2

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

CHANGELOG.md

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,22 +90,33 @@ _**Note:** This is in reverse chronological order, so newer entries are added to
9090
}
9191
```
9292

93-
* References to `optional` methods on a protocol metatype, as well as references to dynamically looked up methods on the `AnyObject` metatype are now supported. These references always have the type of a function that accepts a single argument and returns an optional value of function type:
93+
* References to `optional` methods on a protocol metatype, as well as references to dynamically looked up methods on `AnyObject` are now supported on par with other function references. The type of such a reference (formerly an immediate optional by mistake) has been altered to that of a function that takes a single argument and returns an optional value of function type:
9494

9595
```swift
9696
class Object {
97-
@objc func getTag() -> Int
97+
@objc func getTag() -> Int { ... }
9898
}
9999

100-
@objc protocol P {
100+
let getTag: (AnyObject) -> (() -> Int)? = AnyObject.getTag
101+
102+
@objc protocol Delegate {
101103
@objc optional func didUpdateObject(withTag tag: Int)
102104
}
103105

104-
let getTag: (AnyObject) -> (() -> Int)? = AnyObject.getTag
105-
106-
let didUpdateObject: (any P) -> ((Int) -> Void)? = P.didUpdateObject
106+
let didUpdateObjectWithTag: (Delegate) -> ((Int) -> Void)? = Delegate.didUpdateObject
107107
```
108108

109+
> **Warning**
110+
> Due to the type change, selectors for aforementioned method references that require writing out their type explicitly for disambiguation will no longer compile. To fix this, simply adjust the written type, or resort to a `#if swift(<5.7)` directive when compatibility with older compiler versions is warranted. For example:
111+
>
112+
> ```swift
113+
> #if swift(<5.7)
114+
> let decidePolicyForNavigationAction = #selector(WKNavigationDelegate.webView(_:decidePolicyFor:decisionHandler:) as ((WKNavigationDelegate) -> (WKWebView, WKNavigationAction, @escaping (WKNavigationActionPolicy) -> Void) -> Void)?)
115+
> #else
116+
> let decidePolicyForNavigationAction = #selector(WKNavigationDelegate.webView(_:decidePolicyFor:decisionHandler:) as (WKNavigationDelegate) -> ((WKWebView, WKNavigationAction, @escaping (WKNavigationActionPolicy) -> Void) -> Void)?)
117+
> #endif
118+
> ```
119+
109120
* [SE-0349][]:
110121
111122
Loading data from raw memory represented by `UnsafeRawPointer`,

0 commit comments

Comments
 (0)