|
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 |
|
|
|
GO FURTHER, FASTER Unleash your full potential as a Swift developer with the all-new Swift Career Accelerator: the most comprehensive, career-transforming learning resource ever created for iOS development. Whether you’re just starting out, looking to land your first job, or aiming to become a lead developer, this program offers everything you need to level up – from mastering Swift’s latest features to conquering interview questions and building robust portfolios.
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.