Download image programmatically in fast mode

I have an ImageView. This is the code I use to add an image to ImageView

 var imgstr = pf["ImageFileName"] as String
 image = UIImage(named: imgstr)!
 println(imgstr) //the output here is abc.png
 self.Imageview.image = image

Now I have an image in the Project folder, as you can see in the screenshot Screen shot

However, I get this error at runtime

fatal error: unexpectedly found nil while unwrapping an Optional value
+4
source share
3 answers

Add your images to Images.xcassets

enter image description here

imageView.image = UIImage(named:"abc")
+11
source

How about this?

if let image = UIImage(named:"abc") {
   imageView?.image = image
}
+2
source

put

self.Imageview!.image = image

instead

self.Imageview.image = image
0
source

Source: https://habr.com/ru/post/1583941/


All Articles