I am trying to query my _User class for a specific objectId, and download an image from it.
The objectId passed through the userList is the correct one, if checked against the parse.com user table.
The array returned is always empty
Any help would be appreciated.
func imageArrayFromUserList(userList: [PFUser]) -> [UIImage] {
var arrayToReturn: [UIImage] = []
for user in userList {
let objectID = user.objectId
let query = PFUser.query()
//let query = PFQuery(className: "_User")
query!.whereKey("objectId", equalTo: objectID!)
//query?.limit = 1
query!.findObjectsInBackgroundWithBlock({ (results: [AnyObject]?, error: NSError?) -> Void in
if error != nil{// This never prints anything to console
println(error)
}
if let results = results as? [PFObject] {
for object in results {
let userPicture = object["image"] as! PFFile
userPicture.getDataInBackgroundWithBlock {
(imageData: NSData?, error: NSError?) -> Void in
if error == nil {
if let imageData = imageData {
let image = UIImage(data:imageData)
arrayToReturn.append(image!)
}
}
}
}
}
})
}
return arrayToReturn
}//end of imageArrayFromUserList method
userListis empty so the for loop is never entered. Did you scope outwards with your breakpoints to find out what is getting executed? Put breakpoints to ensure the function is even being entered, and then at the top of the for loop, then at the top of the completion handler.errorparameter? - don't ignore it. Check if it isn't nil and if it isn't then print it to see what went wrong.findObjectsInBackgroundWithBlockis definitely called, so your statement is incorrect. Step through every line of a single interation of theforloop and explain what happens. Are you saying the completion handler is never called? Was a breakpoint ever reached at the top of that?