Download image not being displayed iOS Swift -
i'm trying download images , display them based on different conditions. code worked if download images in main thread, trying download them through end now.
my console clean, i'm not getting errors - yet images not being displayed? first attempt @ doing end image downloading , doing swift come objective-c.
could please @ code below , let me know problem is?
//fizzbuzz image download weak var fizzbuzzimage: uiimage! let fizzbuzzstring = "https://emkaydeum.files.wordpress.com/2015/08/fizzbuzz.png" var fizzbuzzurl:nsurl! //fizz image download weak var fizzimage: uiimage! let fizzstring = "https://vignette2.wikia.nocookie.net/leagueoflegends/images/b/b0/fizz_render.png/revision/latest?cb=20151205185848" var fizzurl:nsurl! //buzz image download weak var buzzimage: uiimage! let buzzstring = "https://vignette2.wikia.nocookie.net/disney/images/b/bc/buzz_disney_infinity_render.png/revision/latest?cb=20140605182818" var buzzurl:nsurl! override func viewdidload() { super.viewdidload() fizzbuzzurl = nsurl(string: fizzbuzzstring) fizzurl = nsurl(string: fizzstring) buzzurl = nsurl(string: buzzstring) } @ibaction func checktextfield(_ sender: uitextview){ enteredvalue = userinput.text let checkifempty = userinput.text?.isempty if (checkifempty == false) { let multipleof3:int = int(enteredvalue)!%3 let multipleof5:int = int(enteredvalue)!%5 if (multipleof3 == 0 && multipleof5 == 0) { fizzbuzz.text = "fizzbuzz" urlsession.shared.datatask(with: (fizzbuzzurl url), completionhandler: {(fizzbuzzdata, resp, error) -> void in if (error != nil && fizzbuzzdata != nil){ operationqueue.main.addoperation ({ self.displayimage.image = uiimage(data: fizzbuzzdata!) }) } }).resume()} else if (multipleof5 == 0){ fizzbuzz.text = "buzz" urlsession.shared.datatask(with: (buzzurl url), completionhandler: {(buzzdata, resp, error) -> void in if (error != nil && buzzdata != nil){ operationqueue.main.addoperation ({ self.displayimage.image = uiimage(data: buzzdata!) }) } }).resume()} else if (multipleof3 == 0){ fizzbuzz.text = "fizz" urlsession.shared.datatask(with: (fizzurl url), completionhandler: {(fizzdata, resp, error) -> void in if (error != nil && fizzdata != nil){ operationqueue.main.addoperation ({ self.displayimage.image = uiimage(data: fizzdata!) }) } }).resume()} else { fizzbuzz.text = "incorrect value" displayimage.image = nil } } }
please check if conditions. have written
if (error != nil && fizzbuzzdata != nil){ operationqueue.main.addoperation ({ self.displayimage.image = uiimage(data: fizzbuzzdata!) }) }
which never executed. please make below
if (error == nil && fizzbuzzdata != nil){ operationqueue.main.addoperation ({ self.displayimage.image = uiimage(data: fizzbuzzdata!) }) }
wiki
Comments
Post a Comment