Swift package
Focused Foundation and standard-library conveniences for repeated low-level work
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.
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.
| Area | Primary APIs |
|---|---|
| Coding | RawCodingKey, keyed-container decode and encode helpers |
| Synchronization | NSLocking.execute, store, mutate, assign |
| Safe access | orThrow, [safe:], clamped(in:), Result.value |
| Projections | Reference, ReadonlyReference, @PropertyProxy |
| Value storage | Box, copy-on-write @Indirect |
| Focused utilities | USID, bundle metadata, regex attribute mapping, casting helpers |