tezvyn:

IBOutlet vs IBAction in Interface Builder

AI-drafted, machine-checkedintermediate
WHAT IT TESTS

grasp of Storyboard-to-code wiring.

OUTLINE

outlet references a view, action handles an event, both connect via Ctrl-drag.

RED FLAG

confusing the two directions or forgetting the connection is runtime, not compile-time.

WHAT THIS TESTS This probes basic familiarity with UIKit and Interface Builder, the historical foundation of iOS UI. Interviewers want to know you can navigate Storyboards and understand how visual elements map to code.

A GOOD ANSWER COVERS An @IBOutlet is a property, usually weak, that gives your code a reference to a view created in the Storyboard, so you can read or change its state at runtime. An @IBAction is a method that the runtime calls in response to a control event such as touchUpInside on a button. The direction differs: outlets flow from interface to code as references, actions flow from interface events to code as callbacks. To connect an outlet you open the assistant editor, Ctrl-drag from the view in the canvas to the class body, choose Outlet, and name it. For an action you Ctrl-drag from the control, choose Action, pick the triggering event, and name the method.

COMMON WRONG ANSWERS Saying the connection is verified at compile time. It is not; a broken connection produces a runtime crash about an unrecognized selector or an unset key value. Another error is reversing the roles, calling the outlet the event handler.

LIKELY FOLLOW-UPS Why are outlets typically weak rather than strong? What happens if you delete a method that still has a Storyboard connection? How do IBOutletCollection or IBInspectable extend this? How would you do the same purely in code without a Storyboard?

ONE CONCRETE EXAMPLE You drag a label onto a view controller and Ctrl-drag it into code as @IBOutlet weak var titleLabel: UILabel!. You add a button and Ctrl-drag it as @IBAction func didTapSave(_ sender: UIButton). Now tapping the button runs didTapSave, which sets titleLabel.text. If you later rename titleLabel without updating the Storyboard connection, the app crashes on load because the runtime cannot set the value for the stale key.

Get five bites like this every day.

Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.