Connecting User Interface to Code

It’s great that our UI handles resizing and orientation changes, but it still doesn’t, y’know, do anything yet.

And that raises an interesting question: how do we get the button tap to do something? After all, we’ve been creating the user interface in the Main.storyboard file, but it doesn’t look like there’s any place in this editor to start writing code.

In iOS, we use Interface Builder connections to tie the user interface to our code. Using Xcode, we can create two kinds of connections:

  • An outlet connects a variable or property in code to an object in a storyboard. This lets us read and write the object’s properties, like reading the value of a slider or setting the initial contents of a text field.

Get iOS 8 SDK Development, 2nd 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.