Current Approach
Keys use the SettingKey<Value> class, which inherits from SettingKeys. This is to allow grouping key definitions under the same namespace as follows:
extension SettingKeys {
static let appLaunchCount = SettingKey<Int>(
"MyAppLaunchCount",
defaultValue: 42
)
}
This structure enables autocomplete and semantic grouping. The tradeoff is extra boilerplate and the need to use classes and inheritance for what are conceptually just values.
Alternatives Considered
- Constrained extensions on
SettingKey – Struct-based and simple, but lacks grouping of related keys. Used by Point-Free’s Sharing library.
- Dynamic member lookup – Only useful for getter/setter. Doesn’t support reset, observation, or publisher APIs.
- Key paths from
SettingKeys to SettingKey – Too verbose and indirect. Cannot use SettingKey directly.
- Protocol-based
SettingKeys – Protocols can't hold stored properties. Would need to go with computed properties.
- Macros – Seems too heavy-weight for this use case.
Current Approach
Keys use the
SettingKey<Value>class, which inherits fromSettingKeys. This is to allow grouping key definitions under the same namespace as follows:This structure enables autocomplete and semantic grouping. The tradeoff is extra boilerplate and the need to use classes and inheritance for what are conceptually just values.
Alternatives Considered
SettingKey– Struct-based and simple, but lacks grouping of related keys. Used by Point-Free’s Sharing library.SettingKeystoSettingKey– Too verbose and indirect. Cannot useSettingKeydirectly.SettingKeys– Protocols can't hold stored properties. Would need to go with computed properties.