Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIWebView LoadData is not accepting Nil values for textEncodingName and baseURL

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 1.2: Works fine

self.webView.loadData(tempData!, MIMEType: "application/pdf", textEncodingName: nil, baseURL: nil)

Swift 2.0: Throws error

self.webView.loadData(tempData!, MIMEType: "application/pdf", textEncodingName: nil, baseURL: nil)
like image 707
Coder Avatar asked Aug 18 '15 23:08

Coder


3 Answers

This works for me:

webView.loadData(pdfDownload, MIMEType: "application/pdf", textEncodingName: "", baseURL: NSURL())
like image 77
EduTgn75 Avatar answered Nov 06 '22 03:11

EduTgn75


Swift 3:

self.webView.loadData(tempData!, MIMEType: "application/pdf", textEncodingName: "UTF-8", baseURL: NSURL() as URL)
like image 23
zoroloco Avatar answered Nov 06 '22 05:11

zoroloco


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())

like image 40
Francesco Vadicamo Avatar answered Nov 06 '22 05:11

Francesco Vadicamo