Swiftpack.co -  noremac/Layout as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
Readable layout constraints.
.package(url: "https://github.com/noremac/Layout.git", from: "3.0.0")


An expressive and extensible DSL for creating Auto Layout constraints and defining declarative layouts.

Availability and Requirements

  • Available as a Swift Package.
  • Requires Xcode 12 or higher.
  • Supports iOS 13+, and tvOS 13+.

Creating Constraints

// Creating inactive constraints (save and activate/manipulate later)
let constraints = view.makeConstraints {
  Size(width: 100, height: 100)
// Creating active constraints
view.applyConstraints {
  Size(width: 100, height: 100)

View builder DSL

Create UIKit layouts with a view builder DSL.

UIStackView.vertical(spacing: 10) {
        .overlay {
            badge.constraints {
                AlignEdges([.bottom, .trailing], insets: 8)
                Size(width: 20, height: 20)
        .constraints {
            AspectRatio(3 / 2)

    UIStackView.vertical(spacing: 10) {


        UIStackView.horizontal {
    .padding(.horizontal, insets: 8)


Generates this layout:


UIView and UILayoutGuide

makeConstraints and applyConstraints operate on both UIView and UILayoutGuide. All constraints that are setup up in relation to other items may also be either UIView or UILayoutGuide.

button.applyConstraints {
  Center(in: view.safeAreaLayoutGuide), // relating to a `UILayoutGuide`
  Size(to: otherButton) // relating to a `UIView`

Constraints that are related to another item default to the receiver’s parent view. Therefore, the following two examples are identical:

// Preferred
button.applyConstraints {
// Not-preferred
button.applyConstraints {
  Center(in: button.superview)

Autoresizing Mask

Layout sets translatesAutoresizingMaskIntoConstraints to false on the receiver of the makeConstraints and applyConstraints calls.

Debugging Constraints

Layout automatically adds debug identifiers to all constraints that include the file, and line number of where the constraint was created.

You may also set custom identifiers:

button.applyConstraints {
  Center() <- "my first custom identifier"


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


Stars: 16
Last commit: 3 weeks 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.

Release Notes

5 weeks ago

The free functions release.

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