Here is a Swift solution:
// objectIds is your array to store the objectId values returned from parse
// objectId is a String
var objectIds:[""] // empty string array
func loadDataFromParse () {
var query = PFQuery(className:"Record")
query.findObjectsInBackgroundWithBlock {
(objects: [AnyObject]!, error: NSError!) -> Void in
if error == nil {
// The find succeeded.
println("Successfully retrieved \(objects.count) scores.")
// Do something with the found objects
for object in objects {
objectIds.append(object.objectId as String)
}
} else {
println("\(error)")
}
}
}
// this function will retrieve a photo in the record with specified objectId
// and store it in noteImage
var noteImage = UIImage() // where retrieved image is stored
func loadImageFromParse (objectId: String) {
var query = PFQuery(className:"Record")
query.whereKey("objectId", equalTo:objectId)
query.findObjectsInBackgroundWithBlock {
(objects: [AnyObject]!, error: NSError!) -> Void in
if error == nil {
println("Successfully retrieved \(objects.count) records.")
for object in objects {
let userImageFile = object["image"] as PFFile!
userImageFile.getDataInBackgroundWithBlock {
(imageData: NSData!, error: NSError!) -> Void in
if error == nil {
noteImage = UIImage(data:imageData)!
println("Image successfully retrieved")
}
}
}
} else {
NSLog("Error: %@ %@", error, error.userInfo!)
}
}
}