I have created a simple project to show a problem that I am running into in a larger project that I am working on.
If you run this code, tap the button to load the image, and then tap the button to remove the image, you will get an error saying "Fatal error: Unexpectedly found nil while unwrapping an Optional value"
It seems to happen because
However, if you run this code, it works just fine...
The only difference being that we are no longer separating the if/else closures into their own separate view structs and passing them a binding to the state variable.
Can anybody explain to me why this happens?
So I slightly altered your code so I could better see what was going on:
Running this, I get the following output in the console (I grouped them for better readability):
You can see that SwiftUI renders all the currently "alive"
It's kind of late and it's been nearly two months since I last watched it, so it will have to wait until tomorrow for a rewatch, but I'm betting the WWDC21 session "Demystify SwiftUI" will be informative here. That session has a lot to say about
Thanks. That did help me to understand a little better.
SPONSORED Superwall lets you build & test paywalls without shipping updates. Run experiments, offer sales, segment users, update locked features and more at the click of button. Best part? It's FREE for up to 250 conversions / mo and the Superwall team builds out 100% custom paywalls – free of charge.
This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.