[ad_1]
I have a struct Settings
. I encode it to JSON with JSONEncoder().encode
and save to UserDefaults
. To load it, I decode it with JSONDecoder().decode
from UserDefaults
Problem: my app is live, and I need to push an update which will introduce new variables to the Settings
struct. After the update, decoding the already saved Settings
struct will fail because the struct is now different.
Question: how do I decode the old saved Settings
struct into the new updated struct? How I see it: I need to decode each key one by one, if it exists in the new Settings
struct – assign it; if it does not – assign new value.
But I have no idea how.
[ad_2]