If you want to shuffle an array use the following method pass an array get the Shuffled Array,
self.shuffledArray = self.ShuffleArray(answersArray: self.answersArray)
func ShuffleArray(answersArray:[String]) -> [String] {
var items = answersArray
var shuffled = [String]();
for _ in 0..<items.count
{
let rand = Int(arc4random_uniform(UInt32(items.count)))
shuffled.append(items[rand])
items.remove(at: rand)
}
return shuffled
}
No comments:
Post a Comment