title: Disable and Enable UIButton - XCode Swift
body: <p>I have made an app that generates a random number and the user must enter a guess and click a button, GUESS to submit. All is working fine. However, I am simply trying to start the app with btnGuess disabled and enabled when a new game is started. The button will also be disabled when the user wins the game. So far, I have searched online and on here as to how you disabled/enable a UIButton and every answer I have found (most notably: button.enabled = false) does not seem to work. Please let me know what I am missing here. I have also tried button.enabled = NO; (which was another offered solution that does not work for me). Thanks.</p>
  
  <pre><code>import UIKit
  
  class myViewController: UIViewController {
  
  var guesses : UInt = 0
  var number : UInt32 = 0
  var inputGuess = 0
  
  
  @IBOutlet weak var lblGuesses: UILabel!
  
  @IBOutlet weak var lblGuessTitle: UILabel!
  
  @IBOutlet weak var lblOutput: UILabel!
  
  @IBOutlet weak var txtInput: UITextField!
  
  @IBAction func txtInput(sender: UITextField){
  
  }
  
  override func viewDidLoad() {
      super.viewDidLoad()
  
      txtInput.enabled = false
      // btnGuess.enabled = false    //doesnt work
  
  
  
      // Do any additional setup after loading the view.
  }
  
  func generateRandom() -&gt; UInt32{
      return arc4random_uniform(100) + 1
  }
  
  func incrementGuesses(){
      ++guesses
      lblGuesses.text = String(guesses)
  }
  
  override func didReceiveMemoryWarning() {
      super.didReceiveMemoryWarning()
      // Dispose of any resources that can be recreated.
  }
  
  @IBAction func btnGuess(sender: UIButton) {
  
      let inputGuess = txtInput.text.toInt()
  
      if UInt32(inputGuess!) &gt; number{
          lblOutput.text = "Too High!"
          incrementGuesses()
      }
      else if UInt32(inputGuess!) &lt; number{
          lblOutput.text = "Too Low!"
          incrementGuesses()
      }else{
          lblOutput.text = "Correct Guess! You Win!"
          guesses = 0
          txtInput.text = ""
          txtInput.enabled = false
          //btnGuess.enabled = false  //doesnt work
  
      }
  }
  
  
  @IBAction func btnStart(sender: UIButton) {
  
      number = generateRandom()
      lblOutput.text = "I'm thinking of a number between 0 - 100"
      lblGuesses.text = "0"
      txtInput.enabled = true
      //btnGuess.enabled = true  //doesnt work
  }
  </code></pre>
  
  <p>} </p>