Last active
August 29, 2015 14:22
-
-
Save simlims/9e2814bf6e59292e6a18 to your computer and use it in GitHub Desktop.
Swift - Quiz App Review
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// **Update Here** | |
// This is how I have tried to go about giving the user their results. | |
// So basically what I tried to do was enumerate the question array and pull out all the users answers and the correct answers and // // append them to a new array. | |
// users answers go to userAnswers | |
// correct answers go to correctAnswers | |
// Then it calls a function checkResults that will check how many answers the user got wrong or right. | |
// This is where I got stuck. I used a map function to compare the 2 arrays and give me a new array back called answer. If the answers // matched the it would return true and if they didn`t it would return false. | |
// Now I am not entirely sure how to convert the results inside answer into Correct or Incorrect. | |
// I tried using something like this: | |
// var finalResults = answer.map({"The following answer is \($0)"}) | |
// But I still do not know the best way to convert the answer array to Strings. | |
// Eventually I plan to display the results of that array into a table view (which I know how to do) so it says something like "This // answer was correct" or "This answer was incorrect". | |
@IBAction func submitAll(sender: UIButton) { | |
let hasAnsweredAllQuestions = questions.reduce(true) { (x, q) in x && (q.usersAnswer != nil) } | |
println("has user answered all questions?: \(hasAnsweredAllQuestions)") | |
for (index, _) in enumerate(questions) { | |
userAnswers.append(questions[index].usersAnswer!) | |
correctAnswers.append(questions[index].answer) | |
} | |
if correctAnswers.count == 3 { | |
checkResults() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment