You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
Thank you! I'm happy to be involved in your first open source contribution!
This sounds like a very sensible addition; it seems like a neat way to expose the key & default value. Can't see any reason to not do it 👍 I'd welcome another pull request.
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 thekey
anddefaultValue
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:
Then, I use a struct to have easy access to all my persisted values:
While that makes it easy to access settings throughout the app:
Settings.plantNameOrder
, it also, along withprojectedValue
makes using this in SwiftUI quite nice: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.
The text was updated successfully, but these errors were encountered: