I am doing a PFQuery on my user class to get images in background.
I have different groups so my goal is to iterate over the groups and get their specific imageData so that I can use them in my UITableView.
In my PFQuery I am using another array temp:[NSData] to store the elements in this array and later to append temp to an array of arrays groupImages:[[UIImage]].
Doing the following query:
note: member:[[AnyObject]] stores the objectId of each group.
let memberImageQuery = PFUser.query()
memberImageQuery?.whereKey("objectId", containedIn: member)
memberImageQuery?.findObjectsInBackgroundWithBlock({ (results, error) -> Void in
if error != nil{
// ...
} else {
if let results = results {
self.temp.removeAll()
for result in results {
let imageFile = result["firstImage"] as! PFFile
imageFile.getDataInBackgroundWithBlock { (imageData: NSData?, error: NSError?) -> Void in
if error != nil {
print("error")
} else {
if let data = imageData {
self.temp.append(data)
}
}
}
self.groupImages.append(self.temp)
}
}
self.tableView.reloadData()
}})
What happens is: temp is basically 0 though printing data in the closure gives back data. The query seems to be correct but the storing of it's data doesn't work. My idea is that it is due to badly structured code.
groupImages.count gives back the right amount of groups
temp.count gives back 0 which is not the right amount of images.