Feb 05, 2018: ~ 3 min read

In a previous post I talked about a new struct (LayoutPriority) and a couple of extension methods on NSLayoutConstraint to ease interacting with them. But, as I later discovered, there is no need for the new struct – we can do the same thing on UILayoutPriority itself. Let's quickly see how.

First, we move all the properties along with the operators to the extension:

The other advantage to this approach is that setContentCompressionResistancePriority:for: and setContentHuggingPriority:for: are using UILayoutPriority, so we can now pass our new constants, instead of creating new methods for those, or bridging LayoutPriority to UIKit: