Marcus Leon
Marcus Leon

Reputation: 56679

Swift: Understanding Outlet linkage

Using the Interface Builder in XCode we control drag from a textfield to the view controller Swift class resulting in this code:

@IBOutlet weak var nameTextField: UITextField!

Now I know that this field links to a specific text field on the storyboard. But how do you look at the this code and determine which textfield this nameTextField attribute refers to?

Upvotes: 0

Views: 117

Answers (2)

matt
matt

Reputation: 535304

But how do you look at the this code

There is no code beyond what you cited:

@IBOutlet weak var nameTextField: UITextField!

The trick is that the name "nameTextField" is also written into the nib file. At runtime, the nib file is loaded and this string is used via key–value coding to match up with the nameTextField property in the nib file's owner (here, the view controller), and the text field instantiated by the loading of the nib is assigned to that property.

Upvotes: 2

Kevin
Kevin

Reputation: 17556

In the editor's gutter there is a grey dot. Click on that and it will give you a link to the storyboard.

The grey dot Link to the storyboard screenshot

If you want to see all of the connections from Interface Builder:

  1. Click on a yellow box for the view controller in IB
  2. Open the Connections Inspector in the right-most box
  3. You'll be able to see all of the connected IBOutlets (you can also hover over one and the view will be highlighted).

Screenshot of viewing IBOutlets

Upvotes: 1

Related Questions