Building a test using swift?

What are the best methods to build a testing application using swift.... All I want is to pick a random questions from a list, with multiple choice answers.


What my logic looks like right now...hey I am new to this...



Class Question{

var question1 = "question 1"

var answer = "a"

}




func get question {

random ????

}



????


Yeah thats about where I am at as a new programmer.

I really appreciate all the help. Thanks.

Accepted Answer

You should post it in Getting started section.


Typically, for this, you could create an array of QA:

struct QA {
   var question: String
   var answer: String 
}

then

var allQA: [QA]


That you populate with your questions.

let qa1 = QA(question: "Who is Steve Jobs", answer: "Apple's Founder")
let qa2 = QA(question: "What is the capital of France", answer: "Paris")
let qa3 = QA(question: "Who was the first man on the moon", answer: "Neil Armstrong")
allQA = [qa1, qa2, qa3]


Then you select a question with a random choice (as an index, or directly random in the array).


let q = allQA.randomElement()!.question
print(q)


So your func is:

func getQuestion() -> String {
     return allQA.randomElement()!.question
}


Now, you have to build the UI for asking question, getting answer and evaluating it.

Building a test using swift?
 
 
Q