I used to save important App data like login credentials into UserDefaults using the following statement:
UserDefaults.standard.set("sample@email.com&quo
We can test this via simple approach:
struct Content: View {
private enum Keys {
static let numberOne = "myKey"
}
@AppStorage(Keys.numberOne) var keyValue2: String = "no value"
var body: some View {
VStack {
Button {
keyValue2 = "Hello"
print(
UserDefaults.standard.value(forKey: Keys.numberOne) as! String
)
} label: {
Text("Update")
}
Text(keyValue2)
}
.padding()
.frame(width: 100)
}
}