I am attempting to retrieve a set of data from a firebase realtime db but I've been unable to get it to wait for the data. Here is the code that starts the process:
if inParm == "Table1" {
loadQuestions1()
myTotal = questionArray.count
loadNextQuestion()
} else {
loadQuestions()
}
Ignore the loadQuestions func that is working since that is pulling from a plist. I'm concerned with the loadQuestions1() func.
Here is the code for that routine
public func loadMultipleExam(forQuiz quizName: String) throws ->
[MultipleChoiceQuestion] {
curCount = 0
maxCount = getCount(forQuiz: quizName)
var questions = [MultipleChoiceQuestion]()
let dbParm1 = "Questions1/" + mySub
let myRef1 = myRef.reference(withPath: dbParm1)
myRef1.observe(.value, with: { snapshot in
for item in snapshot.children {
let mItem = QuestionItem(snapshot: item as! DataSnapshot)
self.questModel.append(Question1(qText: mItem.question, corr: mItem.correctAnswer,
answers:
[
Answer1(text: mItem.answer1),
Answer1(text: mItem.answer2),
Answer1(text: mItem.answer3),
Answer1(text: mItem.answer4)
]
)
)
self.questModel.shuffle()
print(self.questModel)
//self.configureUI(question: self.questModel.first!, myindex: 1)
}
})
return questions
}
Now it fires up to the for statement and then it returns to the if statement and continues through loadNextQuestion which loads the data to the screen but at that point there isn't any. Any help or suggestions would be greatly appreciated.