gpt4 book ai didi

ios - 没有成员名称 'subscript' - SWIFT

转载 作者:行者123 更新时间:2023-11-28 11:21:32 24 4
gpt4 key购买 nike

我正在构建一个问答应用程序,并且我已经开设了一个创建问题的类(class)。我还制作了一个将在 viewDidLoad() 时加载的函数。

 class Question{
var quizQuestion : String = ""
var firstAnswer : String = ""
var secondAnswer : String = ""
var thirdAnswer : String = ""
var fourthAnswer : String = ""
var rightAnswer : Int = 0

init(question:String, answerOne:String, answerTwo:String, answerThree:String, answerFour:String, correctAnswer:Int)
{

self.quizQuestion = question
self.firstAnswer = answerOne
self.secondAnswer = answerTwo
self.thirdAnswer = answerThree
self.fourthAnswer = answerFour
self.rightAnswer = correctAnswer
}
}


let one = Question(question: "What was the first planet to be discovered using a telescope, in 1781?", answerOne: "Mars", answerTwo: "Jupiter", answerThree: "Uranus", answerFour: "Mercury", correctAnswer: 3)

我的 initialState() 函数

 func initialState() {
var firstQuestion: AnyObject = arrayOfQuestions[0]

currentQuestion = 0



questionLabel.text = "\(firstQuestion[0])"

//Setting the buttons text
firstAnswer.setTitle("\(firstQuestion[1])", forState: UIControlState.Normal)
secondAnswer.setTitle("\(firstQuestion[2])", forState: UIControlState.Normal)
thirdAnswer.setTitle("\(firstQuestion[3])", forState: UIControlState.Normal)
fourthAnswer.setTitle("\(firstQuestion[4])", forState: UIControlState.Normal)
}

当我想将按钮文本设置为问题和答案的索引时,它说“问题”没有名为“下标”的成员,这对我来说毫无意义。当我运行该应用程序时,所有内容都设置为“nil”。

有人可以帮忙吗?请解释你的答案,因为我正在努力学习语言和错误。

最佳答案

questionLabel.text = "\(firstQuestion.quizQuestion)"

//Setting the buttons text
firstAnswer.setTitle("\(firstQuestion.firstAnswer)", forState: UIControlState.Normal)
secondAnswer.setTitle("\(firstQuestion.secondAnswer)", forState: UIControlState.Normal)
thirdAnswer.setTitle("\(firstQuestion.thirdAnswer)", forState: UIControlState.Normal)
fourthAnswer.setTitle("\(firstQuestion.fourthAnswer)", forState: UIControlState.Normal)

关于ios - 没有成员名称 'subscript' - SWIFT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27747216/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com