I start quickly and do some tests. Honestly, I barely know what I'm doing, so please try to explain clearly. I was creating an application for a random number generator and wanted to add it to uitextfieldso that the user can enter his guess about the next randomly generated number. I keep getting an error when I try to use the if statement to compare a randomly generated number with the entered number. In the text box.
import UIKit
class ViewController: UIViewController, UITextFieldDelegate {
@IBOutlet weak var input: UITextField!
@IBOutlet weak var infoLabel: UILabel!
@IBOutlet weak var numberLabel: UILabel!
@IBAction func go(sender: AnyObject) {
infoLabel.text = " "
let randomNumber = Int(arc4random_uniform(11))
numberLabel.text = "\(randomNumber)"
if input == randomNumber {
infoLabel.text = "Your Guess,\(randomNumber) Was Correct!"
}
}
override func viewDidLoad() {
super.viewDidLoad()
}
}
source
share