-
Notifications
You must be signed in to change notification settings - Fork 2
Description
First, thanks for letting me contribute (in a small way) to your project. This is the first pull request I've ever done and the first time I've contributed anything to open source!
A suggested feature: add projectedValue to the property wrapper to allow easy access to the key and defaultValue properties. This can be useful when needing to specify these values later, for example, when using @AppStorage in SwiftUI.
Here is an example based on how I'm using this:
In the property wrapper:
public var projectedValue: Self {
return self
}
Then, I use a struct to have easy access to all my persisted values:
struct Settings {
@Persisted(key: "isFirstRun", defaultValue: true)
static var isFirstRun
@Persisted(key: "plantNameOrder", defaultValue: Plant.DisplayNameOrder.botanicalNameFirst)
static var plantNameOrder: Plant.DisplayNameOrder
}
While that makes it easy to access settings throughout the app: Settings.plantNameOrder, it also, along with projectedValue makes using this in SwiftUI quite nice:
struct ContentView: View {
@AppStorage(Settings.$plantNameOrder.key) var plantNameOrder = Settings.$plantNameOrder.defaultValue
// ... rest of implementation
}
Now, instead of having to make sure I get the string for key correct, and use the same default value, I can use what I've already done.
I just thought I'd suggest this based on my own usage. If you don't think this fits here, I totally get it. If you do, I'm happy to do another pull request and add something to the readme that shows this usage.
Thanks again.