I am developing a game for iOS 13 using Xcode 11 and Swift 5. (I'm a beginner.) I have 16 buttons on the screen, and I want to change a button's image and isEnabled setting randomly. I have this function that is called:
func startSequence()
{
timeUntilChange = Int.random(in: 1...2)
nextMole = Int.random(in: 0...15)
timeMoleShows = Double.random(in: 0.5...1.5)
timer = Timer.scheduledTimer(timeInterval: TimeInterval(timeUntilChange), target: self, selector: #selector(showMole), userInfo: nil, repeats: false)
}`
Then I have this:
@objc func showMole()
{
if gameInSession == true
{
moleImage_0.setBackgroundImage(UIImage(named:"mole_t.png"), for: [])
moleImage_0.isEnabled = true
}
}
So where I have moleImage_0 I want the 0 to be the randomly generated number held in the variable "nextMole".
I did search here and found some things about arrays and dictionaries. I tried an array, but couldn't figure it out.
Is what I'm trying to do possible?