Skip to content

Improve ergonomics of defining setting keys #3

Description

@lukaskubanek

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions