-2

I would like to know and learn to solve this kind of the problem.

It keeps telling me that

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

Here is my code:

class ViewController: UIViewController {

    @IBOutlet weak var A1: UIButton!

var player_turn = 0

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
    }

    @IBAction func A1_(_ sender: UIButton) {
        if  player_turn % 2 == 0 {
            A1.setImage(UIImage(named:"King_side.png"), for: .normal)
        }
        else {
            A1.setImage(UIImage(named:"Queen_side.png"), for: .normal)
        }
    }
}
Bhavesh Nayi
  • 3,626
  • 1
  • 27
  • 42
Narsil
  • 1
  • 2

1 Answers1

0

You probably forgot to connect your A1 outlet to a button in your storyboard or XIB.

In general for that kind of error message, take a look at What does "fatal error: unexpectedly found nil while unwrapping an Optional value" mean?.

Steve Madsen
  • 13,465
  • 4
  • 49
  • 67