ios - 对成员 'first(where)' 的模糊引用

标签 ios swift

我正在将 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/

相关文章:

ios - iOS 9 中的点播资源 - 如何找出下载资源的确切位置?

ios - 内部类型配置文件需要 "iOS Development"证书

swift - 你能帮我把多余的刘海去掉吗?

ios - 从父类(super class) iOS swift 中识别子类

ios - 在 iOS (Flutter) 中使用 Firebase 和 Geolocator(或任何 Swift 插件)构建错误

ios - 收到内存警告。 Level=1 - 具有 5 个选项卡的 UITabBarController 应用程序

ios - 如何使用 Swift 从保存在文档目录中的文本中读取字符串?

git - 与私有(private) git 存储库共享 Cartfile?

ios - OBJ-C : Core-Plot XY-Axis Fixing

Swift Realm - 不安全的可变访问器