Getting data from findObjectsInBackgroundWithBlock in swift
I am using Parse to get data from a database. When block-findObjectsInBackgroundWithBlock is called an array, it is passed. Since I only get one row of data, it all appears in one section [0] of the array. So how do I get all the bits from this array?
Here is the code I am working with:
var MainPicture = PFQuery(className: "Staff")
MainPicture.whereKey("Position", equalTo: "Sales Manager")
MainPicture.findObjectsInBackgroundWithBlock ({(objects:[AnyObject]!, error: NSError!) in
if(error == nil){
for object in objects {
}
self.getMainImageData(objects as [PFObject])
}
else{
println("Error in retrieving \(error)")
}
})
so when for an object in objects , it gives me one array with all contents. So how can this array be extracted to get name, last night, location, staff id?
thank
+3
source to share
1 answer
You need to point [AnyObject]
to [PFObject]
, and then you can use standard Parse methods to output the data.
if let staffObjects = objects as? [PFObject] {
for staff in staffObjects {
// Use staff as a standard PFObject now. e.g.
let firstName = staff.objectForKey("first_name")
}
}
+8
source to share