How to add the connection from outlet inspector in Xcode 12

Viewed 1112

I am a newbie to Xcode and programming. I need to establish connections to labels from the connection inspector. I defined the labels but the inspect outlet is not showing them. Below is the code:

Note: using Xcode 12 the newest version.

import UIKit

class GameViewController: UIViewController
{
    @IBOutlet weak var scoreLabel:UILabel?
    @IBOutlet weak var timeLabel:UILabel?
    @IBOutlet weak var numberLabel:UILabel?
    @IBOutlet weak var inputField:UITextField?

    override func viewDidLoad() {
        super.viewDidLoad()
    }
} 
1 Answers

First, in the storyboard, select the view controller and make sure the controllers "class" is defined as GameViewController

View controller class

Once this is done/confirmed, you should be able to flip over to outlet inspector and see the available outlets

Outlets

You should then be able to drag a link from your source code onto the component you want to connect with.

  1. Select the source code view
  2. Click and hold on the outlet marker and
  3. Drag to the component you want to connect to

Link them

You can do in the other direction (from the storyboard to the source code), but you need to hold the [Command] key while you do it

Related