I encountered an issue when implementing the WKUIDelegate
protocol and NSItemProviderWriting
protocol. Below is a minimal example of the code that reproduces the issue:
import UIKit
import WebKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
}
class ItemProvider: NSObject, NSItemProviderWriting {
static var writableTypeIdentifiersForItemProvider: [String] {
fatalError()
}
func loadData(
withTypeIdentifier typeIdentifier: String,
forItemProviderCompletionHandler completionHandler: @escaping @Sendable (Data?, (any Error)?) -> Void
) -> Progress? {
fatalError()
}
}
extension ViewController: WKUIDelegate {
func webView(
_ webView: WKWebView,
runJavaScriptAlertPanelWithMessage message: String,
initiatedByFrame frame: WKFrameInfo,
completionHandler: @escaping @MainActor @Sendable () -> Void
) {
fatalError()
}
}
When implementing the WKUIDelegate
protocol after NSItemProviderWriting
protocol, the following warning appears:
Instance method 'webView(_:runJavaScriptAlertPanelWithMessage:initiatedByFrame:completionHandler:)' nearly matches optional requirement 'webView(_:runJavaScriptAlertPanelWithMessage:initiatedByFrame:completionHandler:)' of protocol 'WKUIDelegate'
The target's SWIFT_VERSION
is 6.0.