Fixed stored @State properties on App #34
Loading…
x
Reference in New Issue
Block a user
No description provided.
Delete Branch "State-property-on-app-fix"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Steps
Purpose
Currently when using a
Stateproperty with storage onAppinstead of on aView, the app ID was accessed before it was set, causing theStateinternals to look for the data in the foldertemporary/which usually doesn't exist because at the time you will be writing into theStatethe app ID will be set and it writes the value intoapp.id/folder.This happened because when the
Stateproperty is onAppit is initialized beforeGTUIApp.appIDis set.Approach
I fixed this by making the
App.idproperty static and forwarding it toGTUIApp.appIDfirst thing the program does. I have also made theGTUIApp.appIDforce unwrapped optional so regression of this issue is not possible.I am open to suggestions of how to fix this differently. You can also fix this yourself in a different way without crediting, it is not that complicated.
Since it is a breaking change I still need to update the examples
Thanks for opening the dicussion and already providing a potential solution! I prefer not to require the user to add a static variable, so I'll see whether I can make the state variables load the files after initializing the app structure. Otherwise, I'll merge your implementation.
Instead of reading the app id at the initialization of a state variable, it will now read it as soon as the value is accessed for the first time. That way, the id property can stay on an app's instance.