Swift package

swift-sharing-extensions

Structured, type-aware keys for PointFree Sharing persistence

Make persistence keys part of the model

String keys are easy to mistype, duplicate, and accidentally change. SharingKeysCore models storage as discoverable domains and entries; SharingKeys connects those declarations to PointFree’s @Shared.

extension InMemoryStorageKeys {
  enum Session: Sendable {}
}

extension StorageKeyBuilder<InMemoryStorageKeys> {
  var session: Subdomain<InMemoryStorageKeys.Session> {
    subdomain()
  }
}

extension StorageKeyBuilder<InMemoryStorageKeys.Session> {
  var draft: Entry { entry() }
  var retryCount: Entry.Strict<Int> { entry() }
}

The hierarchy generates stable, formatted keys while keeping navigation at the call site structural.

@Shared(\.inMemory.session.draft)
var draft = ""

@Shared(.inMemory(\.session.retryCount))
var retryCount = 0

Use Entry.Strict<Value> when a key’s value type is part of its persistence contract. AppStorage domains use the same declaration style and accept an explicit UserDefaults store for suites, app groups, and tests.

The umbrella SharingExtensions product also exposes mutableValue for APIs that require ordinary get/set syntax. Keep compound changes inside one $value.withLock { ... } transaction rather than combining separate reads and writes.

ProductResponsibility
SharingKeysCoreDeclare domains, subdomains, entries, and strict value contracts
SharingKeysConsume structured in-memory and AppStorage keys with @Shared
SharingExtensionsAdd the writable mutableValue facade and umbrella exports

Default keys derive snake-cased components from property names and join the hierarchy with -. Use a full string literal for a legacy key whose persisted spelling cannot change, and pass an explicit UserDefaults store for suites, app groups, or tests.