Let's say I have the following asynchronous query:
var kittens: [PFObject]!
self.tempView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: "pushToView"))
var query = PFQuery(className: "Kittens")
query.findObjectsInBackgroundWithBlock({ (objects, error) in
if let kittenObjects = objects as? [PFObject] {
self.kittens = kittenObjects
}
})
I have a method that presents a view controller:
func pushToView() {
let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let viewController: KittensViewController = mainStoryboard.instantiateViewControllerWithIdentifier("kittensViewController") as! KittensViewController
viewController.kittens = self.kittens
self.presentViewController(viewController, animated: true, completion: nil)
}
Because I'm setting self.kittens
inside of an asynchronous query block it obviously doesn't work when I try to access self.kittens
inside the presented view controller (it's always null).
What's the best method to get something like this working?