Challenge: Add Constraints Programmatically

In this chapter, you added constraints to RaiseMan using Interface Builder. Using the NSLayoutConstraint class, add the same constraints, except for those inside the table view. First, do this using the init(item:attribute:relatedBy:toItem:attribute:multiplier:constant:) API. Second, do it again using the constraintsWithVisualFormat(_:options:metrics:views:) API.

You will need to make sure that the constraints you are adding programmatically do not just duplicate the constraints you already added in Interface Builder. However, removing all constraints from IB will not work, because Interface Builder will detect an ambiguous layout and add constraints to prevent it. Instead, select each of ...

Get Cocoa Programming for OS X: The Big Nerd Ranch Guide 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.