I am trying to access an array using random indexes, using a arc4randomrandom index to generate. I apologize if my “technical use of terms” is incorrect, as I am fairly new to development.
var backLeft = ["Clear","Drop","Smash"];
var i = (arc4random()%(3))
var shot = backLeft[i]
This gives me an error on the third line,
Could not find an overload for 'subscript' that accepts the supplied arguments.
But, if I use,
var i = 2
var shot = backLeft[i]
Then it does not give me any problems. Based on php background, I can not understand what is happening here.
Thanks! :) PS: I try this on XCODE 6 inside the Swift Playground
source
share