参数中的额外调用 - Swift

Extra call in argument - Swift

我正在制作一个问答应用程序,并且正在设置所有问题。我创建了一个函数来更快地提问。但是我遇到了一个错误 'Extra argument in call.'

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。这看起来很简单,但我研究过却发现很少。 感谢您提供任何帮助,请解释您的答案!

您必须在第一个参数之后的每个参数中包含变量描述。

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

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

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)