As far as I could find out, there is no easy random query function in parse. Is there a way to shuffle the objects after I queried them?
query.findObjectsInBackgroundWithBlock { (objects, error) -> Void in
if (error == nil) {
// shuffle objects here?
PFObject.pinAllInBackground(objects, withName:"Card", block: nil)
Any ideas? Thanks!
EDIT: I think the problem is at another point. When I add like in the suggest post (thanks for that) the extension for shuffling, it works like a breeze!
BUT!
query.findObjectsInBackgroundWithBlock { (objects, error) -> Void in
if (error == nil) {
println(objects)
var shuffled = objects.shuffled()
println(shuffled)
PFObject.pinAllInBackground(shuffled, withName:"Card", block: nil)
As you can see, I pin the objects to the local storage.
On my next view I pull this data again out of the storage:
var query = PFQuery(className: "Card")
query.fromLocalDatastore()
query.findObjectsInBackgroundWithBlock { (objects, error) -> Void in
if (error == nil){
println("from local store: \(objects)")
And here I have again the data in the same order as they are saved in the database... There are no shuffled items at all.
Isn't that strange?