Thread 1: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value

I am a beginner to swift language and with the help of apple book, I was typing this code on switching colours using buttons. then in this line: if redswitch.isOn { it is showing this fatal error. What to do I have no idea. Please help me out.

Here's the code: import UIKit

class ViewController: UIViewController {

@IBOutlet weak var colourView: UIView!
@IBOutlet weak var redswitch: UISwitch!
@IBOutlet weak var greenswitch: UISwitch!
@IBOutlet weak var blueswitch: UISwitch!


override func viewDidLoad() {
    super.viewDidLoad()
    
    
    updateColor()
    // Do any additional setup after loading the view.
}
@IBAction func switchChanged(_sender: UISwitch){
    updateColor()
}
func updateColor() {
    var red: CGFloat = 0
    var green: CGFloat = 0
    var blue: CGFloat = 0

    if redswitch.isOn {
        red = 1
    }
    if greenswitch.isOn {
        green = 1
    }
    if blueswitch.isOn {
        blue = 1
    }
    let color = UIColor(red: red, green: green,
       blue: blue, alpha: 1)
    colourView.backgroundColor = color
}

}

The most likely cause of the error is that the outlets are not connected in the storyboard.

Use the connections inspector for the storyboard to check the connections. Open your storyboard in Xcode and choose View > Inspectors > Connections to open the connections inspector.

You may find the following article helpful:

https://www.swiftdevjournal.com/fixing-the-thread-1-fatal-error-unexpectedly-found-nil-while-implicitly-unwrapping-an-optional-value-error/

What @szymczyk said, plus:

You have a small circle on the left of @IBOutlet.

Is it black (then it is connected), or white (then it is not connected and you should connect by ctrl-dragging from one switch in the storyboard to the corresponding @IBOutlet in code).

Thread 1: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value
 
 
Q