Add an outlet connection to send a message to a UI object

To enable your code to send messages to a user interface object, add a connection from the user interface object to a special property in your class called an outlet. For example, if you want to programmatically set the text of a label, add a connection from the label in the user interface file to a label outlet in your code. Interface Builder both adds the declaration for the outlet to your class and connects the instance of your class to the outlet.

  1. In Interface Builder, open the assistant editor (choose View > Assistant Editor > Show Assistant Editor).

  2. Use the jump bar at the top of the assistant editor to select the implementation file of the object that will send the messages.

  3. Control-drag from the object, in the outline view or in the canvas, to the code in the assistant editor.

    Xcode indicates where you can insert an outlet declaration in your code.

  4. In the popover that appears, choose Outlet from the Connection menu, enter the property name, and choose a storage reference type.

    Use a reference type of strong for objects that are not implicitly retained such as gestures and array controllers. For more information, see the View Controller Programming Guide.

    The instance of the class that will be connected to the outlet appears in the Object field.

  5. Click Connect.

    Interface Builder adds the declaration for the outlet to the class. Outlets are defined as IBOutlet properties. The IBOutlet keyword tells Xcode that this property can be connected to your user interface file.

  6. Use the outlet property in your code.

    You can now get and set properties of the object in your code.

SEE ALSOAdd an action connection to receive messages from a UI objectAdd, remove, and modify connections