问题
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