|
14 | 14 | internal import _ForSwiftFoundation |
15 | 15 | internal import CoreFoundation_Private.CFURL |
16 | 16 |
|
| 17 | +#if canImport(os) |
| 18 | +internal import os |
| 19 | +#endif |
| 20 | + |
17 | 21 | /// `_BridgedURL` wraps an `NSURL` reference. Its methods use the old implementations, which call directly into `NSURL` methods. |
18 | 22 | /// `_BridgedURL` is used when an `NSURL` subclass is bridged to Swift, allowing us to: |
19 | 23 | /// 1) Return the same subclass object when bridging back to ObjC. |
20 | 24 | /// 2) Call methods that are overridden by the `NSURL` subclass like we did before. |
21 | 25 | /// - Note: If the `NSURL` subclass does not override a method, `NSURL` will call into the underlying `_SwiftURL` implementation. |
22 | | -internal final class _BridgedURL: _URLProtocol, @unchecked Sendable { |
| 26 | +internal final class _BridgedURL: NSObject, _URLProtocol, @unchecked Sendable { |
23 | 27 | private let _url: NSURL |
24 | 28 | internal init(_ url: NSURL) { |
25 | 29 | self._url = url |
26 | 30 | } |
27 | 31 |
|
| 32 | + private static let logForwardingErrorOnce: Void = { |
| 33 | + #if canImport(os) |
| 34 | + URL.logger.error("struct URL no longer stores an NSURL. Clients should not assume the memory address of a URL will contain an NSURL * or CFURLRef and should not send ObjC messages to it directly. Bridge (url as NSURL) instead.") |
| 35 | + #endif |
| 36 | + }() |
| 37 | + |
| 38 | + override func forwardingTarget(for aSelector: Selector!) -> Any? { |
| 39 | + _ = Self.logForwardingErrorOnce |
| 40 | + return _url |
| 41 | + } |
| 42 | + |
28 | 43 | init?(string: String) { |
29 | 44 | guard !string.isEmpty, let inner = NSURL(string: string) else { return nil } |
30 | 45 | _url = inner |
@@ -384,11 +399,11 @@ internal final class _BridgedURL: _URLProtocol, @unchecked Sendable { |
384 | 399 | } |
385 | 400 | #endif |
386 | 401 |
|
387 | | - var description: String { |
| 402 | + override var description: String { |
388 | 403 | return _url.description |
389 | 404 | } |
390 | 405 |
|
391 | | - var debugDescription: String { |
| 406 | + override var debugDescription: String { |
392 | 407 | return _url.debugDescription |
393 | 408 | } |
394 | 409 |
|
|
0 commit comments