I have an array of random messages, and I want to display one of those messages as output using label and only if the user enters between 1 to 100, so when user enters between 1 to 100 and presses the button the label should generate one of those random messages.
My code:
@IBOutlet weak var outputLabel: UILabel!
@IBOutlet weak var inputTextField: UITextField!
let arrayMessages = ["message 1", "Message 2", "Message 3", "Message 4", "Message 5"]
let numberRange = 1...100
@IBAction func generateButton(_ sender: UIButton) {
let random = Int(arc4random_uniform(UInt32(arrayMessages.count)))
let output = arrayMessages[random]
if (inputTextField.text == numberRange){
outputLabel.text = output
}
}
Aucun commentaire:
Enregistrer un commentaire