Image(uiImage: image ?? UIImage(named: "photo")!)
.resizable()
.frame(width: 300, height: 300)
Crash error
Implicity unwrapped nil value
How can I unwrap this?
Image(uiImage: image ?? UIImage(named: "photo")!)
.resizable()
.frame(width: 300, height: 300)
Crash error
Implicity unwrapped nil value
How can I unwrap this?
How can I unwrap this?
According to the error message, you've got an implicitly unwrapped nil value. That is, you have some variable declared like:
var image: UIImage! = ...
You should only ever use implicit unwrapping when you know for certain that the object will exist as soon as the variable is initialized, and that it will continue to exist for the life of the variable.
The way to fix your problem is to either ensure that the object exists, which is not currently the case since you're getting nil, or stop using implicit unwrapping. You could, for example, change your variable declaration to something like:
var image: UIImage? = ...
Then you'd have a regular optional that you could attempt to unwrap normally as you're doing in the first line of your question.