0

I have

var rockNamesArray:[String] = ["bird", "rock2", "rock3"]

var rockpos = Int(arc4random_uniform(UInt32(3)))

var firstrockString:String = self.rockNamesArray[rockpos]

But its telling me that rockNamesArray isnt a member. Help?

ABakerSmith
  • 22,759
  • 9
  • 68
  • 78

1 Answers1

1

The following works perfectly in a playground.

import Foundation

var rockNamesArray:[String] = ["bird", "rock2", "rock3"]

var rockpos = Int(arc4random_uniform(UInt32(3)))

var firstrockString:String = rockNamesArray[rockpos]

it's not clear from your code if those variables are being declared inside a function or at the class level. The issue is the self. which refers to member variables so I assume the declaration is inside a function etc.

As ABakerSmith hinted - it's really easy to get to the bottom of these kinds of issues by copying & pasting the offending code into a playground.

Damo
  • 12,840
  • 3
  • 51
  • 62