gpt4 book ai didi

ios - 参数中的额外调用 - Swift

转载 作者:行者123 更新时间:2023-11-28 09:15:50 26 4
gpt4 key购买 nike

我正在制作一个问答应用程序,并且正在设置所有问题。我创建了一个函数来更快地提问。但是我遇到了一个错误,即“调用中的额外参数”。

func question(question:String, answerOne:String, answerTwo:String, answerThree:String, answerFour:String, correctAnswer:Int) -> NSArray {

//Set the question
var quizQuestion = question

//set the answers and the right answer
var firstAnswer = answerOne
var secondAnswer = answerTwo
var thirdAnswer = answerThree
var fourthAnswer = answerFour
var rightAnswer = correctAnswer

//Add all the questions and answers to an array
let questionAnswerArray = [question, firstAnswer, secondAnswer, thirdAnswer, fourthAnswer, rightAnswer]

return questionAnswerArray
}


//This next line gives ERROR
var questionOne = question("What month of 1944 did D-Day occur?", "May", "June", "July", "August", 1)

当我尝试调用问题时,它让我可以选择 NSArray 或 String。这看起来很简单,但我研究过却发现很少。感谢您提供任何帮助,请解释您的答案!

最佳答案

不要创建这样的数据数组。而是使用面向对象并创建一个问题类。

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
}
}

var questionOne = Question(question: "What month of 1944 did D-Day occur?",
answerOne: "May", answerTwo: "June", answerThree: "July",
answerFour: "August", correctAnswer: 1)

关于ios - 参数中的额外调用 - Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27745255/

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