sindresorhus/Defaults
67.0
Adequate · 1 October 2026
3.2k
lines of production code
Swift
primary language
2
measurements over time
What this system is
This system is a Swift library that simplifies interacting with UserDefaults by providing a type-safe, protocol-based serialization system for custom types. It enhances developer productivity through Swift macros that enable reactive, observable properties synchronized with UserDefaults and iCloud. The library supports modern Swift concurrency and integrates seamlessly with the Observation framework for automatic UI updates.
Features
Add @ObservableDefault macro for Swift Concurrency
Introduces the @ObservableDefault macro, allowing Defaults keys to be used directly within @Observable classes. This macro generates accessor blocks that integrate with the Observation framework, enabling reactive updates when defaults change. Users must also apply @ObservationIgnored to the property to prevent conflicts with the @Observable macro's own observation mechanisms.
Sources/DefaultsMacros · high confidence
Added Xcode workspace configuration for Swift Package Manager
A new Xcode workspace file (contents.xcworkspacedata) has been added to the .swiftpm directory. This file configures the Swift Package Manager to generate an Xcode workspace that references the package itself, facilitating easier integration and debugging within the Xcode IDE.
.swiftpm · high confidence
Introduce @ObservableDefault macro for reactive UserDefaults properties
This change adds the \@ObservableDefault\ macro, which allows properties to automatically sync with \UserDefaults\ while integrating with Swift's \@Observable\ system. The macro injects custom accessors that read from and write to \UserDefaults\, and sets up an observation listener to update the property when the underlying \UserDefaults\ value changes externally. To prevent infinite recursion during these updates, the implementation uses \Defaults.withoutPropagation\ within the observation callback. The macro requires the property to be a \var\ without an initializer or existing accessor block, and must be provided with a single \Defaults.Key\ argument.
Sources/DefaultsMacrosDeclarations · high confidence
Introduce Defaults.Serializable protocol and bridge system for custom type support
The library now provides a formal \Defaults.Serializable\ protocol and a \Bridge\ system, allowing users to store custom types in \UserDefaults\ by implementing serialization logic. This replaces the previous implicit handling and enables support for complex types like \Codable\ structs, \NSSecureCoding\ objects, and custom collections. The diff also introduces \Defaults.AnySerializable\ for type-erased storage of arbitrary values, adds built-in bridges for \Codable\, \RawRepresentable\, and \NSSecureCoding\ types, and extends support for SwiftUI \Color\, \NSFontDescriptor\/\UIFontDescriptor\, and \UUID\. Additionally, it adds \PreferRawRepresentable\ and \PreferNSSecureCoding\ protocols to let users disambiguate serialization strategies when a type conforms to multiple protocols.
Sources/Defaults · high confidence
Removals
Removed Xcode project and legacy build configuration files
The Xcode project structure (Defaults.xcodeproj), including the project file, test info plists, and shared schemes, has been removed. This indicates a shift away from traditional Xcode workspace management, likely aligning with a move to Swift Package Manager or other build systems, as suggested by the presence of Package.swift in the project history.
Defaults.xcodeproj · high confidence
Test coverage
Added tests for the @ObservableDefault macro and iCloud sync behavior
Added test coverage for the new @ObservableDefault macro, verifying that it correctly expands and synchronizes property values with UserDefaults for various key expression forms (dot syntax, member access, function calls, and stored properties). Additionally, added tests for the iCloud synchronization feature, validating that local changes propagate to the remote store and that external remote changes are correctly reflected in local defaults.
Tests · high confidence
Dependencies
Upgrade to Swift 6.2 toolchain and add macro support
The package now requires the Swift 6.2 toolchain and targets modern platform versions: macOS 11+, iOS 14+, tvOS 14+, watchOS 9+, and visionOS 1+. It introduces a new \DefaultsMacros\ product and associated targets, leveraging the \swift-syntax\ dependency (pinned to version 603.0.2 in Package.resolved) to provide macro capabilities. The \Defaults\ target now includes a privacy manifest resource, and test targets have been expanded to cover the new macro declarations and implementations.
(dependencies) · high confidence
Written by watchdog.canine.dev from the codebase's own history, inside the signed delivery this page is composed from.
How this codebase got here
Score
- CAI 66 → 67 (+0.7)
- Rubric changed (rubric-2026.09.11 → rubric-2026.09.18) — scores are not directly comparable.
Lenses
- Code Health 97 → 97 (+0.0)
- Architecture 100 → 98 (-2.4)
- Maturity 58 → 58 (+0.0)
- Readiness 51 → 55 (+3.6)
- Security 100 → 100 (+0.0)
New (4)
- Coverage not measured — Swift suite
- Inconsistent parameter types for reset operations. Some overloads accept raw String keys, while others accept typed Key<_AnyKey> wrappers. This forces callers to choose between using raw strings (less type-safe) or key wrappers depending on the specific overload signature, creating confusion about the preferred API surface.
- Inconsistent return types for publisher operations. The single-key overload returns KeyChange<Value>, while the multi-key overloads return Void. This inconsistency makes it difficult to handle updates uniformly, as the payload type changes based on the number of keys observed.
- Off the main sequence: Defaults
Written by watchdog.canine.dev from the codebase's own history, inside the signed delivery this page is composed from.
Survey your own repository
sindresorhus/Defaults was measured the same way every project in this corpus was: the same rubric, at a pinned commit, with the result published in full. Point a surveyor at a repository you know and see whether you agree with it.
About this page
- The score is its most recent published measurement, taken on 1 October 2026 at a pinned commit. It is not a live figure and does not change until the project is measured again.
- Measured at commit 00a7465a0668a87fa159e779b9d80f1f9652357e — the exact code this score is about.
- Scored under rubric-2026.09.18 — the same rubric and the same method as every other entry in this index.
- Measured by watchdog.canine.dev using codehealth-analyzer preprod-e569280dd5e2.