I'm new to all of this so I hope this makes sense. I want to display random images when a button is pressed without having the same image appear twice in a row. I have found similar question on this site with answers that have helped, but I am still getting errors in my code that I do not understand.
Here is the code for my image array at the top under the class:
var imageArray:[String] = ["yes", "no", "indeed", "nope", "ofCourse", "noWay"]
Here is the code I am using for the random numbers under the button IBAction: (there are probably mistakes in this I'm not aware of, like I said earlier I am a noob)
var currentNo: UInt32 = 0
func randomNumber(maximum: UInt32) -> Int {
var randomNumber: UInt32
do {
randomNumber = (arc4random_uniform(6))
}while currentNo == randomNumber
currentNo = randomNumber
return Int(randomNumber)
}
var imageString:String = self.imageArray [randomNumber]
self.iPhoneImage.image = UIImage(named: imageString)
I'm getting an error on this line:
var imageString:String = self.imageArray [randomNumber]
It says
"Cannot subscribe value of type '[String]' with an index of type '(UInt32) -> Int'