-1

Is there anyway we can select Random Collection view element form the list using Swift.

Arun Kumar
  • 139
  • 1
  • 13

2 Answers2

1

You can use arc4random_uniform to select a random index in the array.

For example:

let array = [AnyObject]()
let randomIndex = arc4random_uniform(UInt32(array.count))
let randomItem = array[randomIndex]
Jacob King
  • 6,025
  • 4
  • 27
  • 45
  • I don't have any array list. I have a collection view `XCUIApplication().collectionViews.staticTexts["ABC"]` from this collection view I would like to select one. – Arun Kumar Oct 06 '16 at 13:55
0

you can use something like this,

var myString = moodArray[arc4random() % moodArray.count]

It will select random element from your array.

Now you have to create new array with this random value and display it in uicollection view.

KAR
  • 3,303
  • 3
  • 27
  • 50