title: how to change uiimage's image on button click in swift?
body: <p>I'm trying change an uiimage control's containing image by clicking a button in swift. For this, i wrote a simple a "guess how many fingers i'm holding up" app. I've read some stackoverflow articles but couldn't solve the problem. Below you can see my code and my ui. How can i change change image on click?</p>
  
  <p>Here's my code:</p>
  
  <pre><code>import UIKit
  
  class ViewController: UIViewController {
  
      @IBOutlet var myImageView: UIImageView!
      @IBOutlet var inputField: UITextField!
      @IBAction func clickedGuessButtonAction(sender: AnyObject) {
          println("Guess button clicked")
          var randomX = Int(arc4random()%6)
          println("randomX = \(randomX)")
          var guess = inputField.text.toInt();
  
          let image0 = UIImage(named: "images/qm.jpg")
          let image1 = UIImage(named: "images/tick.jpg")
          let image2 = UIImage(named: "images/cross.jpg")
  
          if((inputField.text) != nil){
              if(guess == randomX){
                  println("correct")
                  myImageView.image=UIImage(named: "tick.jpg") // THIS IS NOT WORKING
                  myImageView.image=image1                     // THIS IS NOT WORKING TOO
                  inputField.resignFirstResponder();// hides keyboard
              }
              else
              {
                  println("wrong")
                  myImageView.image=UIImage(named: "cross.jpg")
                  inputField.resignFirstResponder();//hides keyboard
              }
          }
          else{
              println("invalid input. requires integer only")
              inputField.resignFirstResponder();// hides keyboard
          }
      }
  
      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>
  
  <p>And here's my UI:</p>
  
  <p><img src="https://i.stack.imgur.com/9guk9m.png" alt="enter image description here"></p>