title: How to change an image in SWIFT depending on a variable, clicking a button that uses an IF statement
body: <p>This is a simple program that creates a random number and compares it to a number that the user inputs in a text field. It's basically a "guess how many fingers i'm holding up?" program.</p>
  
  <p>What I want to do is to display an image in the UIImageView depending on the "var randomNumber" when the user guessed correctly, and an image (cross) for when the user guesses incorrectly or has input a number higher than 5. The image shows a question mark at the beginning. The images from 0-5 are images showing 5 fingers to none accordingly.</p>
  
  <p>Do I have to specify the images like this? Do i need to write down the extension of the file?</p>
  
  <pre><code>hand.image = UIImage(named: "0")
  hand.image = UIImage(named: "1")
  hand.image = UIImage(named: "2")
  hand.image = UIImage(named: "3")
  hand.image = UIImage(named: "4")
  hand.image = UIImage(named: "5")
  hand.image = UIImage(named: "wrong")
  hand.image = UIImage(named: "?")
  </code></pre>
  
  <p>or like this?</p>
  
  <pre><code>let image0 = UIImage(named: "0")
  let image1 = UIImage(named: "1")
  let image2 = UIImage(named: "2")
  let image0 = UIImage(named: "3")
  let image1 = UIImage(named: "4")
  let image2 = UIImage(named: "5")
  let image0 = UIImage(named: "wrong")
  let image1 = UIImage(named: "?")
  </code></pre>
  
  <p>Do I need to specify them at all?</p>
  
  <p>Nothing has worked so far, would be nice if someone could help. The app crashes every time I press the "Guess Button". It's a fairly easy task, but as i'm just starting out i would like to know how it's done. Thanks in advance.</p>
  
  <p>This is my code so far.</p>
  
  <pre><code>//
  //  ViewController.swift
  //  Finger Raten
  //
  //  Created by Daniel Bleyer on 04.07.15.
  //  Copyright (c) 2015 DiBi. All rights reserved.
  //
  
  import UIKit
  
  class ViewController: UIViewController{
  
  @IBOutlet var hand: UIImageView!                   //image view
  
  @IBOutlet weak var output: UILabel!                 //result (right/wrong)
  
  @IBOutlet weak var input: UITextField!              //guessed number
  
  @IBAction func guess(sender: AnyObject)        //guess button (comparing both numbers)
  
  {
  
  
      var randomNumber = arc4random_uniform(6)  //random number
  
      var inputInt = input.text.toInt()                            //guessed number
  
      hand.image = UIImage(named: "0")          //does this code go here? or somewhere else?
      hand.image = UIImage(named: "1")          //does this code go here? or somewhere else?
      hand.image = UIImage(named: "2")          //does this code go here? or somewhere else?
      hand.image = UIImage(named: "3")          //does this code go here? or somewhere else?
      hand.image = UIImage(named: "4")          //does this code go here? or somewhere else?
      hand.image = UIImage(named: "5")          //does this code go here? or somewhere else?
      hand.image = UIImage(named: "wrong")  //does this code go here? or somewhere else?
      hand.image = UIImage(named: "?")          //does this code go here? is it RIGHT? This image
                                                                        //shows at the beginning, it is a question mark.
  
  
      if inputInt != nil &amp;&amp; inputInt &lt; 6                                                     //conditions (not empty/0-5)
  
      {
  
          if inputInt == Int(randomNumber)                                             //comparing random/guessed
  
          {
  
          output.text = "Right !";                                                              //right guess
          hand.image = UIImage(named: "\(randomNumber)")              //image showing 0-5 fingers
                                                                                                           //is this the right place?
              input.resignFirstResponder();                                              //hides numpad
  
          } else  {
  
                  output.text = "Wrong, it was a \(randomNumber)";          //wrong guess, it was a ??
                  hand.image = UIImage(named: "wrong)")                       //image of a cross (X)
                                                                                                           //is this the right place?
                      input.resignFirstResponder();                                      //hides numpad
                  }
  
  
      } else  {
  
              output.text = "Enter a number from 0-5";                             //field empty or out of range
              hand.image = UIImage(named: "wrong")                            //image of a cross (X)
                                                                                                           //is this the right place?
                  input.resignFirstResponder();                                          //hides numpad
              }
  }
  
  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.
      }
  }
  </code></pre>