Instance member cannot be used on type 'ViewController'

二次信任 提交于 2019-11-29 09:50:27

If the code you pasted is not defined in a method like viewDidLoad, you cannot use a variable thats defined at the class level for another variable thats defined at the class level as well. These variables are determined at run time and the order they are determined is not known so fortuneArray may not exist before randomIndex is made (might not really work like this behind the scenes but you can think of it this way at least)

you should compute these variables inside viewDidLoad or init or some other function instead

Ah, I figured it out with Fonix's help. I declared the random number in an IBAction and that took care of it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!