Creating IBActions and IBOutlets L2.2.2

Targets and Actions

IBActions are used to connect UIElements to view controller code. In the case of a button it will link the pressing of the button to the function that contains the code to be executed when that event happens. This is called a target action, the target is the view controller and the action is the function to be executed.

To wire that up from the storyboard you can ctrl-click and drag from the element in the document outline and by selecting action from the dropdown

drag and drop

This will cause a little filled in bubble next to the new IBAction function to indicate that it is connected to a UIElement

IBOutlets are used to wire up a connection from code to a UIElement. The process for creating an IBOutlet is similar to creating an IBAction. The same ctrl-click drag process is used but instead we keep the dropdown set to Outlet. This will create an element that looks something like this with the type and name set from the pop up form.

@IBOutlet weak var myLabel: UILabel!

popup menu