Skip to content →

Naming Interface Builder Outlets and Actions

Ever wondered how to name an @IBOutlet property or @IBAction method and felt conflicted over “the right way to do it”? You’re not alone:

In case that’s you, here’s the Apple-sanctioned convention:

  • For @IBOutlets, the property name comes in two parts. First, begin with a description of the contents of the control, such as username, passcode, or authenticationNotification. Then add the name of the control, such as Label, TextField, and Button. The result: usernameLabel, usernameTextField, and passcodeButtons. Examples of what not to do: trustAgentUsername: UITextField and authenticationNotification: UILabel.
  • For @IBActions, the method name simply describes the action; there is no control name suffix as with an @IBOutlet. For example, a UIButton action that capitalizes a word in an associated UITextField would be properly declared func capitalizeWord(sender: UIButton). An action that removes a user would be func removeUser(sender: UIButton). Examples of what not to do: didTapButtontappedDone, or overlayTap.

Specific Apple resources prescribing and modeling this convention include their “Start Developing iOS Apps (Swift)” guide, specifically Lesson 3, “Connecting the UI to Code“, and their discussion on Target-Action in the “Concepts in Objective-C Programming” documentation. Their Swift API Design Guidelines say nothing on the matter, presumably deferring to their elsewhere-stated conventions.

A corroborating resource I found is Matt Thompson’s “IB Outlet / IB Action / IB Collection” article., while also corroborating, has little to say on this specific issue, giving but one example (out of this particular context, even) of an @IBAction between their Objective-C and Swift style guides.

If you have found yourself asking, “How do I name my IB connections?”, hopefully this clears things up for you. It’s not complicated; it’s just a matter of knowing.

Published in Standards


Leave a Reply

Your email address will not be published.