ios - UIWebView for GIF Background loadData method error -
i keep receiving same error of: cannot invoke loaddata argument of list type '(nsdata, mimetype: string, textencodingname: nil, baseurl: nil)'
for loaddata method.
var filepath = nsbundle.mainbundle().pathforresource("fractal", oftype: "gif")  var gif = nsdata(contentsoffile: filepath!)  var webviewbg = uiwebview(frame: self.view.frame)  webviewbg.loaddata(gif!,mimetype: "image/gif",textencodingname: nil,baseurl: nil) // line of code causes build error 
you should check loaddata function signature, is:
func loaddata(_ data: nsdata, mimetype mimetype: string,   textencodingname textencodingname: string, baseurl baseurl: nsurl) textencodingname string, not string?, can't pass nil. same applies baseurl type nsurl, not nsurl?.
in case, can pass whatever values utf-8 , http://localhost/ meet non-nil criteria.
check this thread other ways how it.
try minimize usage of ! avoid runtime failures. more robust:
guard let filepath = nsbundle.mainbundle().pathforresource("fractal", oftype: "gif"),   let gifdata = nsdata(contentsoffile: filepath) else {     return }  var webviewbg = uiwebview(frame: self.view.frame) webviewbg.loaddata(gifdata, mimetype: "image/gif", textencodingname: "utf-8",   baseurl: nsurl(string: "http://localhost/")!) 
Comments
Post a Comment