Swiftpack.co - dehesa/Autolayout as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
Non verbose way to create constraints and work with anchors
.package(url: "https://github.com/dehesa/Autolayout.git", from: "1.0.0")

Logo & Name

Non verbose way to create constraints and work with anchors.

Swift 5.* platforms License

This framework provides:

  • Operators (custom and overloads) for anchors and constraints. Let you define constraints simply and clearly.
    view.topAnchor == superview.topAnchor ~ .high + 10
    It also lets you store the constraint after definition.
    let constraint = view.topAnchor == superview.topAnchor ~ .high ↑ "CustomIdentifier"
  • Anchor groups. Autolayout provide group of anchors that usually perform similar operations. Such as horizontal anchors (left, right), directional anchors (leading, trailing), edge anchors (top, left, bottom, right), etc.
    scrollview.edgeAnchor == superview.edgeAnchor
    It lets you work with anchor groups similarly than you would work with simple anchors.
    scrollview.edgeAnchor == superview.edgeAnchor + 5 ~ .low
  • Constraint containers. It let you store or access easily constraints created through anchor groups.
    let container = view.directionalEdgeAnchor >= superview.directionalEdgeAnchor + 3 ~ .required
    container.leading.constant = 10
    container.bottom.isActive = true
    Autolayout lets you perform normal constraint operations on the whole constraint container.
    container.constant = 10
  • Compile-time constraint creation checks. You can only perform operations on compatible types. For example, none of following lines will compile:
    view.horizontalAnchor == superview.directionalAnchor
    view.sizeAnchor >= superview.verticalAnchor


This code and tool is under the MIT License. See LICENSE file in this repository.

Any ideas and contributions welcome!


This framework was initially influenced by Anchorage by Raizlabs. Although the syntax is similar, Autolayout provide a completely different internals and generics system to facilitate compile-time checks and group operations (such as activity or constant settings).

In any case, Anchorage is still a great tool that I thoroughly recommend to anyone ;)


Stars: 2
Last commit: 1 week ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Submit a free job ad (while I'm testing this). The analytics numbers for this website are here.

Release Notes

SPM Support
2 years ago

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics