Reputation: 1331
I have an ImageView. This is the code I am using to add image to the 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 the image in my Project folder as you can see in the screenshot
Still I am getting this error at run time
fatal error: unexpectedly found nil while unwrapping an Optional value
Upvotes: 5
Views: 25548
Reputation: 2535
What about this?
if let image = UIImage(named:"abc") {
imageView?.image = image
}
Upvotes: 3
Reputation: 3759
Add your images to Images.xcassets
imageView.image = UIImage(named:"abc")
Upvotes: 17
Reputation: 6092
put
self.Imageview!.image = image
instead of
self.Imageview.image = image
Upvotes: 0