|
my code is here: basicslly what i think is happening is that as i rotate the device the views are thrown away and recreated and as such lose all state. how do i fix this without a 'global' somewhere? |
|
Hi, You need to go "one level up" with the selectedItem @Binding, try with this:
|
|
Hi. thank you so much for your reply. Doesn't this solution break the concept of it being a reusable view? If the core mechanic is stored 'outside' of the view itself, this would break core software engineering concepts. is there another way that doesnt violate them and keeps the component reusable? |
|
Well the other way i could think of is using @Appstorage and storing the selected item that way, but maybe somebody else has a better idea. |
|
|
|
I made a small class as the 'source of truth'. It's working now, but I'm still unhappy that I had to do that. Thanks for your help. |
SPONSORED Alex is the iOS & Mac developer’s ultimate AI assistant. It integrates with Xcode, offering a best-in-class Swift coding agent. Generate modern SwiftUI from images. Fast-apply suggestions from Claude 3.5 Sonnet, o3-mini, and DeepSeek R1. Autofix Swift 6 errors and warnings. And so much more. Start your 7-day free trial today!
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.