Ib outlet and action

What is the difference between an outlet and an action ? When should either one of them be used ?

IBOutlet and IBActions are two important concepts when it comes to making the View and Controller interface of your product.

IBOutlets are just referring to the UI element on the storyboard, while IBAction is a function tied to said element and updates the view accordingly. IBOutlets are comparable to instance variables that you can update. IBActions take in the result of the event and change the corresponding storyboard in some fashion. IBActions returns a void whenever it's called.

Example of IBOutlet:
@IBOutlet weak var foobarButton: UIButton!

Example of IBAction:
@IBAction func buttonPressed(_ sender: UIButton) { // Do something }

Further explanation is explained by Paul Hudson on the Hacking with Swift site:

1 Like
Terms of Service

Privacy Policy

Cookie Policy