Instance member cannot be used on type 'ViewController'

后端 未结 2 992
無奈伤痛
無奈伤痛 2020-12-18 23:48
class ViewController: UIViewController {    

let fortuneArray = [\"You will find true love in the summer.\", \"Outlook not good\", \"You may find great success in b         


        
相关标签:
2条回答
  • 2020-12-19 00:04

    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

    0 讨论(0)
  • 2020-12-19 00:20

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

    0 讨论(0)
提交回复
热议问题