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

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -