I had a similar situation when I had to run the view as soon as the data was retrieved from the Parse server. I used the following:
func fetchQuestionBank(complete:()->()){ let userDefault = NSUserDefaults.standardUserDefaults() let username = userDefault.valueForKey("user_email") as? String var query = PFQuery(className:"QuestionBank") query.whereKey("teacher", equalTo: username!) query.findObjectsInBackgroundWithBlock { (objects:[AnyObject]?, error:NSError?) -> Void in if error == nil { if let objects = objects as? [PFObject] { var questionTitle:String? var options:NSArray? for (index, object) in enumerate(objects) { questionTitle = object["question_title"] as? String options = object["options"] as? NSArray var aQuestion = MultipleChoiceQuestion(questionTitle: questionTitle!, options: options!) aQuestion.questionId = object.objectId! InstantlyModel.sharedInstance.questionBank.append(aQuestion) } complete() } }else{ println(" Question Bank Error \(error) ") } } }
And you call the method:
self.fetchQuestionBank({ () -> () in
source share