Why is my UILabel variable always nil?
<p>I am simply trying to connect a variable with a UILabel in Swift. I have looked at many tutorials but I keep getting errors. The main cause seems to be that <code>@IBOutlet weak var str = UILabel!</code> is always nil. When I try to assign a value to it, the console prints a <code>fatal error: unexpectedly found nil while unwrapping an Optional value</code> and inside the coding interface, the line <code>self.stringLabel.text = self.string</code> is highlighted with the error <code>Thread 1: EXC_BAD_INSTRUCTION(code=EXC_I386_INVOP,subcode=0x0</code>. Here is my code: </p>

<pre><code>@IBOutlet weak var stringLabel: UILabel!
var string: String!

override func viewDidLoad() {
    self.stringLabel.text = self.string
    super.viewDidLoad()
}

@IBAction func buttonClick(sender: UIButton) {
    self.stringLabel.text = "Button clicked!"
}
</code></pre>

<p>I have tried different positioning of the <code>.self</code> and <code>.text</code> around the variables and have had no success. Am I on the right track? And, if so, what amI doing wrong? If I'm completely wrong, how does one set a label's text to that of a variable? Thank you very much in advance.</p>

<p>EDIT: I have connected the label in the storyboard to the <code>@IBOutlet</code></p>

<p>e </p>