Swiftpack.co - Package - noremac/Layout

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.


Readable layout constraints.


Swift 5.0 Carthage compatible

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

Creating Constraints

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

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.

  .center(in: view.safeAreaLayoutGuide), // relating to a `UILayoutGuide`
  .relativeSize(of: 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
// Not-preferred
  .center(in: button.superview)

Autoresizing Mask

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

Debugging Constraints

Layout has the ability to add debug identifiers to all constraints that include the file, function, and line number of where the constraint was created. If you are having trouble with ambiguous constraints, you can enable these identifiers like this:

// Call this in your AppDelegate
ConstraintGroup.debugConstraints = true

Declarative Layout




Layout has not yet been published as a CocoaPod, but you may still use it.

To integrate Layout into your Xcode project using CocoaPods, specify it in your Podfile:

pod 'Layout', :git => 'git@github.com:/noremac/Layout.git', :tag => '0.0.2'


To integrate Layout into your Xcode project using Carthage, specify it in your Cartfile:

github "noremac/Layout"

Run carthage update to build the framework and drag the built Layout.framework into your Xcode project.


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