I save the selectedIndex of some segmented pickers in UserDefaults when values change. I want to restore these values to set the pickers when reopening the App. The kicker is that these settings are utilized in a number of views and subsequently the pickers are tied to @State variables. State vars are immutable so my code:
@State var abc:Int
Picker("Type by", choice: $abc)
let person = UserDefaults.normal
$abc = person.integer(forKey: "abc")
I get the compile errors:
Can’t assign to property: ‘$abc’ is immutable
Can’t assign worth of kind ‘Int’ to kind ‘Binding’
What’s the manner round this?