0

I started programming with Swift recently. One thing was working in the beginning but not anymore. When I control-drag a label from my Storyboard to my code to connect it (IBOutlet and IBAction in Swift) the @IBOutlet ends up in viewDidLoad() {} and I get an error.

import UIKit

class ViewController: UIViewController {




    @IBOutlet weak var x1: UILabel!
    @IBOutlet weak var x2: UILabel!
    @IBOutlet weak var x3: UILabel!
    @IBOutlet weak var x4: UILabel!

    var rowLabels = [UILabel]()

    override func viewDidLoad() {

        super.viewDidLoad()

// should be below the other outlets instead!?!
// Error: Only instance properties can be declared @IBOutlet
        @IBOutlet weak var x5: UILabel!


        SetupMyThings()

    }

I get rid of the error by moving the code up but how do I get it to be there in the first place?

Community
  • 1
  • 1
joeswift
  • 21
  • 2

1 Answers1

0

First remove all references in storyboard Go to storyboard, select the label In the properties inspector, select the last one reference inspector Remove all if any of them are present

Next Simply write @IBOutlet weak var x5: UILabel! Now control drag from the label into the variable Your problem will get solved

This is another way to connect outlets and actions