ViewController.Type does not have a member names 'answerOne' - SWIFT

前端 未结 1 1476
陌清茗
陌清茗 2021-01-25 03:34

I am making a swift app. It is a trivia app for fun and I have run into an issue that I havent seen before. (I am new to swift and ios development errors)

impor         


        
相关标签:
1条回答
  • 2021-01-25 04:28

    Solution 1 : Your code is not inside a method, you have to wrap it inside the method. Check this stackoverflow answer

    Solution 2 : Keep your questions and answers inside struct and access them, if you don't want to wrap it inside a function.

    struct firstQuestion {
        static var question = "What was the first planet to be discovered using the telescope, in 1781?"
        static var answerOne = "Mercury"
        static var answerTwo = "Uranus"
        static var answerThree = "Venus"
        static var answerFour = "Jupiter"
        static var correctAnswer = "Correct Answer"
    }
    
    var questionOneArray = [firstQuestion.answerOne, firstQuestion.answerTwo, firstQuestion.answerThree, firstQuestion.answerFour, firstQuestion.correctAnswer]
    
    0 讨论(0)
提交回复
热议问题