1

When I run the app, I keep getting the error:

"Could not cast value of type 'Swift._NSContiguousString' to 'NSArray'." 

I've tried casting to a String as well, but that obviously wasn't the solution either. Has anyone encounter this? I'm just trying to pull a random string from the array.

firstArray = ["firstItem", "secondItem", "thirdItem"]
randomArray = firstArray[Int(arc4random_uniform(UInt32(firstArray.count)))] as! NSArray

Thanks

Victor Sigler
  • 23,243
  • 14
  • 88
  • 105
Calvin
  • 13
  • 4

1 Answers1

2

Keep your array defined as the following :

var firstArray = ["firstItem", "secondItem", "thirdItem"]

Then do the random number from here :

 let randomIndex = Int(arc4random_uniform(UInt32(firstArray.count)))

Get the result like this :

var result = self.firstArray[randomIndex]

Good luck !

AaoIi
  • 8,288
  • 6
  • 45
  • 87