A Swift micro-library for creating new types with compile-time guarantees using custom validators.
Validated is a Swift micro-library that provides tools for creating new types with built-in validation guarantees. It allows developers to encode business rules and invariants directly into the type system, turning runtime checks into compile-time errors. This approach helps catch invalid data earlier and makes code signatures more expressive.
Swift developers building applications where data integrity and invariants are critical, such as those working on safety-critical systems, complex domain models, or anyone seeking to reduce runtime crashes and improve code clarity.
Developers choose Validated because it offers a lightweight, composable way to leverage Swift's type system for validation, eliminating the need for repetitive runtime checks and documentation. Its micro-library design and support for generic validators make it easy to integrate and extend.
A Swift μ-Library for Somewhat Dependent Types
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
By encoding invariants into type signatures, Validated catches invalid data at compile time, as shown in the LoggedInUser example, eliminating the need for runtime precondition checks and documentation.
Validators can be combined using logical operators like And, Or, and Not, enabling complex validation rules, such as creating an AllCapsNonEmptyString type from multiple validators.
As a micro-library with ~50 SLOC, it's easily added via CocoaPods or Carthage, making it a minimal dependency for Swift projects seeking enhanced type safety.
The README explicitly states it doesn't enable dependent types; it only validates against statically defined categories, limiting dynamic type creation based on values.
Each validation requires defining a custom validator and type alias, which can be overkill for straightforward checks like non-empty strings or numeric ranges.
Validation fails silently with nil or throws generic errors, lacking rich error details for debugging or user-facing messages compared to traditional runtime validation.