A declarative Auto Layout DSL for Swift that replaces verbose constraint code with clean, readable syntax.
Cartography is a Swift library that provides a declarative domain-specific language (DSL) for Apple's Auto Layout system. It simplifies creating and managing UI constraints by replacing verbose, boilerplate code with clean, readable expressions using natural operators. It solves the problem of Auto Layout's cumbersome API, making UI code more maintainable and less error-prone.
iOS and macOS developers building native apps with Swift who use Auto Layout for interface design and want a more expressive, maintainable way to define constraints.
Developers choose Cartography because it dramatically reduces Auto Layout boilerplate, improves code readability with a Swift-native DSL, and provides features like constraint groups and compound attributes that aren't available in vanilla Auto Layout.
A declarative Auto Layout DSL for Swift :iphone::triangular_ruler:
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Uses intuitive operators like ==, +, and - to write constraints, replacing verbose NSLayoutConstraint code with readable expressions, as shown in the README's comparison example.
Automatically sets translatesAutoresizingMaskConstraints to false for views in constraints, reducing boilerplate and potential errors in manual setup.
Supports attributes like size, center, and edges to set multiple constraints at once, simplifying common layout tasks such as centering a view or applying insets.
Allows capturing and replacing groups of constraints dynamically, enabling smooth animated layout changes with UIView.animate, as demonstrated in the replacing constraints section.
In Xcode 11 and Swift 5.1, the 'constrain' function conflicts with CommonUISDK, requiring explicit module naming (Cartography.constrain), which adds complexity and can break code if not handled.
The library has separate versions for Swift 3.x, 4.x, and 5.x, leading to potential breaking changes and maintenance hurdles when updating Swift, as noted in the versioning section.
Only supports Auto Layout for UIKit and AppKit, making it irrelevant for SwiftUI or cross-platform projects, and less future-proof as Apple shifts towards declarative UI frameworks.