Last active
October 10, 2023 02:39
-
-
Save StewartLynch/ae8efa87a15f9efce48b41350080809a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Observable class SomeClass { | |
// @AppStorage("name") var name = "" // Does not work | |
/// This will do the same thing | |
var name: String { | |
get { | |
access(keyPath: \.name) | |
return UserDefaults.standard.string(forKey: "name") ?? "" | |
} | |
set { | |
withMutation (keyPath: \.name) { | |
UserDefaults.standard.setValue (newValue, forKey: "name") | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment