Constraint Macros

Constraints provide reliable components for view layout. That said, in their native form, constraints are both overly verbose and fundamentally redundant. You end up implementing the same complex hard-to-read calls over and over again.

Debugging constraints is a real pain. Simple typos take too much effort, and constraints tend to be the same from app to app. A repository of predefined macros saves time and increases the readability and reliability of the view layout sections. Instead of centering a view inside another view and having to debug that layout each time you implement it, a single CENTER_VIEW macro does the job consistently each time.

Creating macros, as shown in Listing 5-1, shifts the work from producing exact ...

Get The Core iOS Developer’s Cookbook, Fifth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.