Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting data from findObjectsInBackgroundWithBlock in swift

I am using Parse to get data out of a database. When the block - findObjectsInBackgroundWithBlock is called an array gets passed. As I am only receiving one row of data, it all appears in one [0] section of the array. So how do i get all the bits out of that array ??

Here is some code I 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 where for object in objects is , it gives me one array with all the stuff in. So how can extract that array to get the First Name, Last Night, location, Staff ID out ?

thanks

like image 761
Jason Avatar asked Aug 01 '26 19:08

Jason


1 Answers

You'll need to cast your [AnyObject] to a [PFObject] and then you can use the standard Parse methods to get the data out.

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")
  }
}
like image 179
rickerbh Avatar answered Aug 04 '26 18:08

rickerbh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!