UIWebView's “loadData” method does not accept nil for baseURL in Swift 2

百般思念 提交于 2019-12-12 14:18:39

问题


I don't want to pass any value to baseURL parameter in loadData method of UIWebView.

In Swift 1.2, nil works fine:

self.loadFundInfo.loadData(responseData, MIMEType: contentType, textEncodingName: "", baseURL: nil)

In Swift 2.0, how to do the same thing?

I am getting this error:

Nil is not compatible with expected argument type NSURL


回答1:


The error message is rather self-explanatory: the baseURL parameter must now be of type NSURL, not NSURL? (not an optional anymore, so it can not be nil).

Method signature in Swift 2 is:

loadData(data: NSData, MIMEType: String, textEncodingName: String, baseURL: NSURL)

The answer is you can't do the same thing, you have to provide a base URL.



来源:https://stackoverflow.com/questions/32761819/uiwebviews-loaddata-method-does-not-accept-nil-for-baseurl-in-swift-2

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!