UIWebView LoadData is not accepting Nil values for textEncodingName and baseURL

前端 未结 4 2048
旧时难觅i
旧时难觅i 2021-02-03 12:03

Till Swift 1.2 version, UIWebView LoadData was accepting nil values, but Swift 2.0 is throwing error \"Swift does not conform to protocol NilLateralConvertible\".

Swift

相关标签:
4条回答
  • 2021-02-03 12:44

    The default character encoding is UTF-8 so you can do in this way:

    self.webView.loadData(tempData!, MIMEType: "application/pdf", textEncodingName: "UTF-8", baseURL: NSURL())

    0 讨论(0)
  • 2021-02-03 12:44

    Apple has updated the declarations and they now require non-nil values. They have adding reality to the declarations for the benefit of Swift (and ObjC).

    - (void)loadData:(NSData   * nonnull)data
            MIMEType:(NSString * nonnull)MIMEType
    textEncodingName:(NSString * nonnull)encodingName
             baseURL:(NSURL    * nonnull)baseURL
    
    0 讨论(0)
  • 2021-02-03 12:48

    This works for me:

    webView.loadData(pdfDownload, MIMEType: "application/pdf", textEncodingName: "", baseURL: NSURL())
    
    0 讨论(0)
  • 2021-02-03 12:52

    Swift 3:

    self.webView.loadData(tempData!, MIMEType: "application/pdf", textEncodingName: "UTF-8", baseURL: NSURL() as URL)
    
    0 讨论(0)
提交回复
热议问题