I cannot get a [UIImage?] return from this function. The getDataInBackgroundWithBlock
won't let me set a return value other than Void in
. However, that block does add to the iconArray
as it iterates through. But once outside of the block the array is empty again. You will see in the code below the comments where the array does and does not print correctly.
The call does connect to the DB, all data is flowing. It's simply returning that array that is the hang up.
class callData {
func queryImages() -> [UIImage?] {
var iconArray: [UIImage?] = []
var query: PFQuery = PFQuery(className: "QuestionMaster")
query.findObjectsInBackgroundWithBlock { (objects: [AnyObject]?, error: NSError?) -> Void in
for object in objects! {
let imageFiles = object["questionImage"] as! PFFile
imageFiles.getDataInBackgroundWithBlock({
(imageData: NSData?, error: NSError?) -> Void in
if (error == nil) {
let image = [UIImage(data: imageData!)]
iconArray += image //adds item to array correctly
}
println(iconArray) //prints correct array here
}) //getDataInBackgroundWithBlock close
println(iconArray) //does not print correct array here
} //for-loop close
}
return iconArray //returns empty array
}
}