I have class like this below to pick questions from plist, but now I want to take them in random order
class QuizLoader {
public func loadSimpleQuiz(forQuiz guizName: String) throws -> [SimpleQuestion] {
var questions = [SimpleQuestion]()
if let path = Bundle.main.path(forResource: guizName, ofType: "plist") {
if let dict = NSDictionary(contentsOfFile: path) {
let tempArray: Array = dict["Questions"]! as! [Dictionary<String,AnyObject>]
for dictionary in tempArray {
let questionToAdd = SimpleQuestion(question: dictionary["Question"] as! String, correctAnswer: dictionary["CorrectAnswer"] as! String)
}
return questions
} else {
throw LoaderError.dictionaryField
}
} else {
throw LoaderError.pathField
}
}
I was trying to do this with this hint but I have error with var unsignedArrayCount = UInt32(quoteDictionary.count)
I have already spend few hours trying to figure it out, but still no luck.
Aucun commentaire:
Enregistrer un commentaire