Closed Vincz closed 2 years ago
I personally only use Codable structs when I need to have multiple instances, for example, in an array. Codable structs have the downside of being harder to change as you cannot later on add a non-optional property to it without some kind of migration. So in general, I prefer namespacing on the key name, like you have done above.
There's no support for observing nested properties and I don't think there will be. There's little benefit to it unless properties on the struct change extremely often.
@sindresorhus Thank for you reply, it makes perfect sense. I will use the namespacing strategy when I can.
Hi guys :) I'm using the Defaults package to store various configuration objects. It looks as follow:
It's working well when I'm using the base keys (ie.
display
andauth
). I'm using@Default
in my views andDefaults.observe
sometimes. Now I would like to be able to use@Default
orDefaults.observe
on a nested key.Something like
@Default(.display["spacing"])
in my view orDefaults.observe(.display["spacing"])
to observe only a subset.Is it possible or should I move all the nested keys at the root level like for easy access:
Or should I use the custom types to do that? https://github.com/sindresorhus/Defaults#custom-types But I'm not sure to understand correctly as the example so a really simple struct.
Thanks guy!