|
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 |
|
|
|
SPONSORED AppSweep by Guardsquare helps developers automate the mobile app security testing process with fast, free scans. By using AppSweep’s actionable recommendations, developers can improve the security posture of their apps in accordance with security standards like OWASP.
Sponsor Hacking with Swift and reach the world's largest Swift community!
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.