I am trying to fetch some data from the backend and then assign it to 3 different arrays. These arrays I then want to use to populate my tableViewCells. The issue is, when I print my arrays outside of the fetch block, they return nil. When I print them in the fetch block, they return the object's variables which I intend it to do so.
I include the self.tableView.reloadData() line in the hope that the arrays get populated and subsequently fill the tableViewCells, but it doesn't seem to be working.
Any suggestions welcomed on how to get those arrays populated correctly so when I print them outside of the fetch request they return the appropriate data.
var capArray = [String]()
var imageDic = [String: [PFFile]]()
var priceArray = [Int]()
override func viewDidAppear(animated: Bool) {
capArray.removeAll(keepCapacity: true)
imageDic.removeAll(keepCapacity: true)
priceArray.removeAll(keepCapacity: true)
let query = PFQuery(className: "SellerObject")
query.findObjectsInBackgroundWithBlock { (objects, error) -> Void in
if let objects = objects {
for o in objects {
if o.objectForKey("caption") != nil && o.objectForKey("imageFile") != nil && o.objectForKey("price") != nil {
let cap = o.objectForKey("caption") as? String
self.capArray.append(cap!)
let imdic = o.objectForKey("imageFile") as? [PFFile]
self.imageDic[cap!] = imdic
let price = o.objectForKey("price") as? String
let priceInt = Int(price!)
self.priceArray.append(priceInt!)
}
}
}
}
self.tableView.reloadData()
}