0

So, I am very new to XCode and Swift. I am having trouble changing the title text on a UIButton, and I keep getting the error

fatal error: unexpectedly found nil while unwrapping an Optional value

This is my code :
//
//  ViewController.swift
//  mtgHealthTracker
//
//  Created by Reagan McFarland on 5/1/16.
//  Copyright © 2016 Reagan McFarland. All rights reserved.
//

import UIKit

class ViewController: UIViewController {
    //Mark : Properties


    @IBOutlet weak var btnPlayer1Health: UIButton!
    @IBOutlet weak var btnPlayer4Health: UIButton!
    @IBOutlet weak var btnPlayer3Health: UIButton!
    @IBOutlet weak var btnPlayer2Health: UIButton!

    @IBOutlet weak var lblCurrWinner: UILabel!

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    //Mark Actions
    @IBAction func btnPlayer1HealthChanged(sender: UIButton, forEvent event: UIEvent) {
        btnPlayer1Health.setTitle("Hello World", forState: UIControlState.Normal)

    }

    @IBAction func btnPlayer2HealthChanged(sender: UIButton, forEvent event: UIEvent) {
    }

Help is greatly appreciated! Thanks :)

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Reagan McFarland
  • 295
  • 1
  • 10
  • 2
    Also see http://www.raywenderlich.com/10209/my-app-crashed-now-what-part-1 to learn how to debug a crash. – rmaddy May 01 '16 at 23:28

1 Answers1

1

One or more of your IBOutlet's are not connected within your XIB/Storyboard. Make sure to select your File's Owner and drag your IBOutlet to your XIB/Storyboard element.