I want to apply images to 3 random UIButtons amongst my 12 UIButtons in total.
My idea to make it work;
I generate 3 random numbers between 1-12. Depending on the 3 random numbers I will use if-statements to interact with the different buttons. Example;
Code generates 3 random numbers that I hold in a variable: var numbers = (1, 2, 3)
Then I use an if-statement to check if the variable holds any number equal to 1
if numbers == 1 {
//code
}
Then make this same if-statement for all twelve of my buttons (if numbers == 2 | if numbers == 3 | if numbers == 4...) And so on. The problem is you can't do this if-statement.
Here is my try at making the example above;
var numbers = Array(0...12)
numbers.shuffled()
var pick3numbers = numbers.choose(3)
So far so good, it generates three random numbers kept in var pick3numbers now to my issue;
I want to make an if-statement depending on the random numbers kept in var pick3numbers. However, I can't make the if statement I want to; (example;)
*If any of the three* numbers == 1 {
self.button1.setImage(UIImage(named: "code2"), forState: .Normal)
}
Am I stepping in mud or can this actually be done somehow?
Aucun commentaire:
Enregistrer un commentaire