A collection of Swift property wrappers to simplify and enhance Codable implementations by handling edge cases gracefully.
BetterCodable is a Swift library that provides a suite of property wrappers for Swift's Codable protocol, designed to eliminate boilerplate and handle common JSON decoding pitfalls automatically. It allows developers to write cleaner, more robust models without custom initializers, making API integration smoother and less error-prone.
Swift developers working with JSON APIs, particularly those dealing with inconsistent or malformed data, mixed date formats, or needing to avoid optional containers and custom decoding logic.
Developers choose BetterCodable because it offers declarative, type-safe solutions for real-world JSON decoding challenges through property wrappers, reducing manual error handling and custom init(from:) implementations compared to vanilla Codable.
Better Codable through Property Wrappers
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Automatically handles common cases like null filtering and default values, removing the need for custom initializers as shown with @LossyArray and @DefaultCodable examples in the README.
Allows per-property date strategies (e.g., ISO8601, RFC3339) decoupling from JSONDecoder, enabling mixed formats in a single model without tight coupling.
Provides lossless type conversion for inconsistent APIs, such as converting Int to String with @LosslessValue, preserving data integrity without manual decoding.
Uses Swift's property wrappers for clean, readable code that clearly expresses intent, reducing manual error handling and improving maintainability.
For edge cases beyond built-in wrappers, developers must implement custom strategies, which the README admits requires additional work despite being 'a sinch'.
Property wrappers introduce runtime overhead during decoding, such as filtering in @LossyArray, which can impact performance in high-frequency or large-data scenarios.
Adopting the library ties your codebase to its API, with potential breaking changes from Swift updates or library evolution, and it requires Swift 5.1+ for property wrappers.