This question already has an answer here:
In my application, I use something like this to get random text on my label, except in my main let randomNumber
code, in xCode, it has over 300 cases, to much to paste in here.:
let randomNumber = Int(arc4random_uniform(23))
var textLabel = "" as NSString
switch (randomNumber){
case 1:
textLabel = "Kim."
break
case 2:
textLabel = "Phil."
break
case 3:
textLabel = "Tom"
break
case 4:
textLabel = "Jeff"
break
default:
textLabel = "Austin"
}
self.randomLabel.text = textLabel as String
But the problem is, that sometimes it shows the same text on the label 5-6 times, and other cases is not even used yet, because it choose randomly. So how can I choose randomly, but if case example case 1 is already shown, it wont show up again, until all other cases has been shown.
Have an array of Names instead of a gigantic switch case:
This ensures every name gets printed before starting from the beginning again. The sample output is:
and then it starts again
Finally put something like the following wherever it fits your need: