I have an array of functions (around 250) for my quiz application that provides all the information for the quiz. This includes the question, answer, explanation & after the user has submitted their answer it includes the user answer.
Before each quiz I want to shuffle all the array and select 50 questions and use them. Would I need to make a new array that holds the 50 questions and transfer the 50 randomly selected questions into that. If so, how exactly do I go about doing that.
Also what would be the best way to store the 250 question array. Do I store that in another swift file and again, if so, how would I do that efficiently.
Thanks
class QuizQuestion {
let question: String!
let answer: Bool!
let explanation: String!
var usersAnswer: Bool?
var answerSubmitted: Bool?
static var dog = 1
init(question: String, answer: Bool, explanation: String) {
self.question = question
self.answer = answer
self.explanation = explanation
}
}
let questions = [
QuizQuestion(question: "Do I like coffee?", answer: true, explanation: "Because it's awesome!"),
QuizQuestion(question: "Is bacon god's gift to mankind?", answer: true, explanation: "Because it's awesome!"),
QuizQuestion(question: "Should I take a nap right now?", answer: true, explanation: "You gotta review some code!"),
]
Aucun commentaire:
Enregistrer un commentaire