I'm using @AppStorage with a String property. When changing the value of the property, the view automatically updates to reflect the change as expected. However, the majority of the time it hasn't persisted in UserDefaults. I'm feeling daft with the idea i've missed something here. Is anyone else seeing this?
Steps:
- Launch app
- Change value
- Kill and re-launch app
- Change value to something else
- Kill and re-launch app
Environment:
- Xcode 13.4 (13F17a)
- iOS 15.5 - iPhone 13 Pro Simulator
Very simple example:
struct ContentView: View {
@AppStorage("token") var token: String = ""
var body: some View {
Form {
Section("Token") {
Text(token)
}
Section("Debug") {
Button("Update 01") {
token = "token-01"
}
Button("Update 02") {
token = "token-02"
}
}
}
}
}
