If you wrote a non-trivial iOS app in 2016, you had to deal with Auto Layout, and dealing with Auto Layout in code meant either Interface Builder (no thanks) or typing out monstrosities like:
addConstraint(NSLayoutConstraint(
item: view1, attribute: .right, relatedBy: .equal,
toItem: view2, attribute: .left, multiplier: 1.0, constant: -12.0
))
Mortar was my take on the same problem that SnapKit and Cartography were solving — turn Auto Layout into something you’d actually want to type. I just preferred operator overloading to closures and method chains. The line above collapses to:
view1.m_right |=| view2.m_left - 12.0
|=|, |>|, and |<| cover the three constraint relations. Multipliers and
constants are just multiplication and addition. Composite attributes like
m_size, m_edges, and m_center let you constrain whole frames in a single
line. Arrays let you apply the same constraint to a batch of views at once.
Priorities ride on a ! operator: view1 |=| view2 ! .low.
Underneath, it’s still a 1:1 mapping to NSLayoutConstraint — no magic, no
hidden constraint solver, no surprises. Just a DSL that’s a lot less painful
to read and write.