Hello fellows I am studying iOS development with Apple’s Education book Develop with Swift Fundamentals Xcode12 and went into peculiar crush right into the beginning of the course about IBOutlets and IBActions.
So during the lab I was needed to create UILabel and UIButton that changes UILabel on the press but the program crushes during runtime with “Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value”. I do get its crashes due to nil optional unwrapping but I don’t get why since I a bit newbie here :(
My ViewController code is below
//
// ViewController.swift
// InterfaceBuilderBasics
//
// Created by Shun Kaido on 09.11.2021.
//
import UIKit
class ViewController: UIViewController {
@IBOutlet var mainLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
@IBAction func changeTitle(_ sender: Any) {
mainLabel.text = "This app rocks!"
}
}
@OOPer Thank you! It’s as you said! Somehow IBOulet circle for UILabel wasn’t filled so I had to re-made IBOutlet for that element.
But what I don’t get is that programmatically it was OK. Why then it didn’t work? What causes IBOutlet to lose it’s connection? I did it as usual by dragging with Control + Click :(