我正在将 UIWebView 迁移到 WKWebView。更改所有内容后面临一个错误 对成员“first(where)”的引用不明确。帮我解决这个问题。
UIWebView
func share(sender: UIWebView) {
if let url: URL = webViews.first?.request?.url {
do {
let base64Data = try Data(contentsOf: url)
let documentURL = try savePDF(base64Data)
documentInteractionController = UIDocumentInteractionController(url: documentURL)
documentInteractionController?.presentOptionsMenu(from: shareButton, animated: true)
} catch {
displayAlert(Localizations.Error, message: Localizations.Apierror, responder: nil, completion: nil)
}
}
}
我把上面的代码改成了WKWebView
WKWebView
func share(sender: WKWebView) {
if let url: URL = webViews.first?.load?.url
{
do {
let base64Data = try Data(contentsOf: url)
let activityController: UIActivityViewController = UIActivityViewController(activityItems: [base64Data], applicationActivities: nil)
present(activityController, animated: true, completion: nil)
} catch {
displayAlert(Localizations.Error, message: Localizations.Apierror, responder: nil, completion: nil)
}
}
}
在这一行中遇到错误 if let url: URL = webViews.first?.load?.url
最佳答案
WKWebView
没有属性 load
,只有 load(_:)
。也许你想做的只是:
if let url = webViews.first?.url {
// ..
}
关于ios - 对成员 'first(where)' 的模糊引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46086558/