O'Reilly logo

Cocoa Programming for OS X: The Big Nerd Ranch Guide by Aaron Hillegass, Adam Preble, Nate Chandler

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required