Swift package

swift-foundation-extensions

Focused Foundation and standard-library conveniences for repeated low-level work

Remove repeated low-level plumbing

FoundationExtensions is a toolbox rather than a framework. Import it when one focused helper makes an invariant clearer, then keep the surrounding code conventional.

let snapshot = lock.execute {
  storage
}

let item = items[safe: index]
let token = optionalToken.orThrow(MissingToken())
let progress = rawProgress.clamped(in: 0...1)

The locking helpers keep compound reads and mutations inside one transaction. Optional, collection, range, and Result helpers give common checks names without forcing a new application architecture.

Better shapes for state

Use Reference<Value> for a closure-backed read/write projection, Box when a value needs reference identity, and @Indirect for copy-on-write recursive storage.

struct ListNode<Value> {
  var value: Value

  @Indirect
  var next: ListNode<Value>?
}

let status = Reference.object(model, keyPath: \.status)
  .onChange { logger.log($0) }

For Codable, RawCodingKey and the container helpers make ad-hoc wire keys practical without declaring a one-use enum. The package also includes property proxies, bundle metadata, identifiers, attributed-string transforms, and Objective-C utilities – use the narrow feature that removes repetition and leave the rest on the shelf.

AreaPrimary APIs
CodingRawCodingKey, keyed-container decode and encode helpers
SynchronizationNSLocking.execute, store, mutate, assign
Safe accessorThrow, [safe:], clamped(in:), Result.value
ProjectionsReference, ReadonlyReference, @PropertyProxy
Value storageBox, copy-on-write @Indirect
Focused utilitiesUSID, bundle metadata, regex attribute mapping, casting helpers