I am very new to swift and cant figure out how to programmatically change the picture in a UIImageView. i have tried this so far:
if let image = UIImage(named: "mouse.jpg") {
imageView.image = image
print("image set")
}
but it causes the found nil while unwrapping an optional fatal exception.
mouse.jpg is in the same folder as the swift file and can be set as the image views image in the inspector in Xcode.
wrapping the code in another if like this:
if let iv = imageView{
if let image = UIImage(named: "mouse.jpg"){
iv.image = image
}
}
fixes the nil error but does not change the picture at all from what was set in the storyboard.
any ideas would be helpful