Making Connections

Creating views and laying out your user interface is not the only purpose of Interface Builder. You can also use Interface Builder to wire up connections between your views and your Swift code.

Setting target-action pairs for VocalTextEdit’s buttons

When you run your application and Main.storyboard is loaded, the Cocoa runtime will create an instance of your ViewController class, configure its views, and set up any outlets and actions you have configured. For VocalTextEdit, you want the speakButtonClicked(_:) method to be called on the instance of ViewController that is managing the current document. Control-drag from the Speak button to the icon representing the ViewController, as in Figure 26.19.

Get Swift Programming: The Big Nerd Ranch Guide now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.