'Pass Binding<String> to UserDefaults-Swift
I created a watchos App that asks the user for his weight and want to store the weight's value in Userdefaults. The code is as follows
...
@State var weight: String = ""
var body: some View {
ScrollView{
VStack(alignment: .leading) {
TextField("Enter height...", text: $weight)
.onAppear(){
UserDefaults.standard.setValue(weight, forKey: "userWeight")}
...
}
}
When I read the userdefaults userweight is "".
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
