成员的模糊提及' first(where)'

时间:2017-09-07 01:33:08

标签: 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

1 个答案:

答案 0 :(得分:1)

WKWebView没有属性load,只有load(_:)。也许你想做的只是:

if let url = webViews.first?.url {
    // ..
}