class ViewController: UIViewController { let fortuneArray = ["You will find true love in the summer.", "Outlook not good", "You may find great success in business soon.", "Watch out for grey cats."] let randomIndex = Int(arc4random_uniform(fortuneArray.count)) override func viewDidLoad() { super.viewDidLoad() let randomIndex = Int(arc4random_uniform(UInt32(fortuneArray.count))) print("random index: ") print(randomIndex)
I am creating a very simple fortune-telling app in Swift, and I continue to run into problems with arc4random_uniform . I'm currently just trying to get the application to draw a string at random, but I get an error:
Instance member 'fortuneArray' cannot be used for type 'ViewController'
in the line where I declare the variable randomIndex . I have been using Google for a while but have not found a fix. Hope someone can help, thanks!
* Update * The problem is solved! Thanks.
source share