A Swifty and modern type-safe wrapper for UserDefaults with SwiftUI support and iCloud sync.
Defaults is a Swift library that wraps Apple's UserDefaults API with a type-safe, modern interface. It solves the problem of verbose and error-prone UserDefaults usage by allowing developers to declare strongly-typed keys with default values upfront. The library adds features like SwiftUI property wrappers, observation, and support for Codable types, making persistent storage simpler and more robust.
Swift developers building iOS, macOS, tvOS, watchOS, or visionOS apps who need a better way to handle persistent user preferences and app state. It's especially useful for developers using SwiftUI who want reactive updates when UserDefaults values change.
Developers choose Defaults because it eliminates the stringly-typed nature of raw UserDefaults, reduces boilerplate, and provides a seamless SwiftUI experience. Its production-ready reliability, extensive type support, and iCloud synchronization offer a comprehensive solution that goes beyond Apple's built-in @AppStorage property wrapper.
💾 Swifty and modern UserDefaults
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Declares types and default values upfront using strongly-typed keys, eliminating stringly-typed errors and ensuring safety at compile time, as emphasized in the README.
Provides a @Default property wrapper that automatically updates views when UserDefaults values change, seamlessly integrating with SwiftUI's state management for reactive UIs.
Supports storage of any Codable value, including enums and custom types, with built-in serialization, reducing boilerplate compared to manual UserDefaults handling.
Enables easy observation of key changes without NotificationCenter boilerplate, facilitating reactive programming patterns in both SwiftUI and non-SwiftUI contexts.
Only compatible with macOS 11+, iOS 14+, and newer, which excludes apps that need to support older operating systems and devices.
Requires defining keys in a Defaults.Keys extension, adding boilerplate code that might be unnecessary for very simple storage needs compared to raw UserDefaults.
Introduces an external library that must be maintained and updated, whereas Apple's @AppStorage is built-in and less prone to breaking changes or compatibility issues.