Add, remove, and modify connections

In Interface Builder, change an object’s connections to other objects in a user interface file using the connections panel. After making a connection directly to your source code, you may need to change or remove the connection. The connections panel shows you all the connections to and from an object and makes it possible to change or remove them.

The specific connections listed in the connections panel depend on the object you select. Types of connections include Cocoa Touch events, actions, outlets, outlet collections, and bindings. If a connection exists, the circle on the right (called a connection well) is filled in and the name of the connected object is shown. You add connections by dragging from the connection well to an object or source code.

You can also change an object’s connections using the Connections inspector (). To show the Connections inspector, choose View > Utilities > Show Connections Inspector.

Connect from an object to code

If you connect an object to source code, you add the declaration in the class and the outlet or action connection at the same time. You can also connect an object to an existing method in source code.

  1. In Interface Builder, Control-click an object to open the connections panel.

  2. Open the assistant editor (choose View > Assistant Editor > Show Assistant Editor).

  3. Use the jump bar at the top of the assistant editor to select the implementation file for the outlet or action.

  4. In the connections panel, drag from a connection well (open circle on the right side of an outlet or action) to the code in the assistant editor.

    Xcode indicates where you can insert an outlet or action method in your code. If you hover over a method, Xcode indicates whether it can be the action for a target.

Connect from one object to another

If the outlet or action already, you make a connection between objects without changing the source code.

  1. In Interface Builder, Control-click an object to open the connections panel.

  2. In the connections panel, drag from a connection well to the other object in the outline view or canvas.

    Xcode indicates where you can insert an outlet or action method in your code. If you hover over a method, Xcode indicates whether it can be the action for a target.

  3. If you drag from an action method, in the dialog that appears, choose an event for the action.

Delete a connection

  1. In Interface Builder, Control-click an object to open the connections panel.

  2. In the connections panel, click the Delete button (x) to the left of the connection name.

SEE ALSOAdd an outlet connection to send a message to a UI objectAdd an action connection to receive messages from a UI object