0
votes

Can't find the answer to this anywhere.

After I call a pfquery, how do I add PFObjects to an array? I have this so far

var array = [PFObject]()

and

var query = PFQuery(className: "Stores")

EDIT: I want to append PFObjects from Parse to an array, so I can then shuffle the order of objects randomly. I know Parse doesn't have the ability to fetch objects randomly

1
i mean.. edit with your current code. - adolfosrs

1 Answers

0
votes

You may use .extend method.

Try initialize your array like this:

var array: [PFObject] = []

And when calling the find method try the following:

 var query = PFQuery(className:"Stores")
            query.findObjectsInBackgroundWithBlock {
                (objects, error) -> Void in
                if (error == nil) {
                    //casting object as [PFObject] since objects is [AnyObject]
                    self.array.extend(objects as! [PFObject])
                    println(self.array)
                }else {
                    println(error?.userInfo)
                }
            }