Here is a piece of code where from the array of items is taken from 1 to 3 elements (there are 21 of them). I need to make sure that once you click on an item it does not disappear, but appear (from those that have already been taken) from 1 to 3 (randomly).

 @IBOutlet var items: [UIButton]! @IBAction func itemsHidden(sender: UIButton!) { if items.count > 0 && aiDeciding == false { if moveCount < 3 { sender.hidden = true if let index = items.indexOf(sender) { items.removeAtIndex(index) //вот что я пробовал let numberToInsert = Int(arc4random_uniform(UInt32(3))) for _ in 0..<numberToInsert { let tag = Int(arc4random_uniform(UInt32(items.count))) items[tag].hidden = false items.append(tag) } } } } } 
  • Once again, what should you do? - Max Mikheyenko
  • Example: start the game. I take 2 elements, the opponent takes 3, I am alone, etc. BUT! at one of the moments (which is determined randomly) when you click on an element, it does not disappear, but on the contrary, from those that have already been taken, would appear in an amount from 1 to 3 (randomly). - Spartak
  • you need to create an array and put in it all the elements that have already been taken. when a button is pressed, use arc4random_uniform(x) and if the value you need has come, then again using random select how many elements you want to appear and show them. In other words, you want to write a lot of business logic. Try to specify the question somehow, if you have something concrete that does not work. - Max Mikheyenko
  • added a piece of code that I tried. But he is incorrect. Where there is a mistake, I do not understand ... - Spartak
  • in your code, you select a random object from the array and make it visible, that is, most likely you just stumble upon an object that is already visible and that's it. - Max Mikheyenko

1 answer 1

you need to create an array and put in it all the elements that have already been taken. When a button is pressed, use arc4random_uniform(x) and if the value you need has come, then again using random select how many elements you want to appear and show them.