Explaining and Implementing IBOutlets in Swift Programming using Xcode

In iOS programming, IBOutlets are very commonly used. This post will explain what IBOutlets are.

IBOutlets connect your code to your UI Elements. Each UI Element must be connected to an IBOutlet in order for the code to be able to control its attributes. Adding an IBOutlet is very simple.

The first step is to click on the button in the top right corner. The button looks like the image below.

Now, from the file viewer on the left, click you viewcontroller’s file. Make sure your view controller in the storyboard is connected to your view controller swift file. You can check this by clicking on the View Controller in the storyboard, clicking on the newspaper icon* in the pane to the right, and making sure the class is the file desired.

*This is how the newspaper icon looks like

Lastly, control+click (or right click) and drag your UI Element (uilabel, uitextfield, uitextview, etc.) to just below the class declaration in your viewcontroller file. Now let go, give your IBOutlet a name and hit enter or click the button. The IBOutlet has been successfully added.

Click the X button (as shown above) to switch back to single file view

A post about IBActions will be released soon.

Leave a Comment

Your email address will not be published. Required fields are marked *