Thursday, 15 May 2014

ios - swift parse: How to shuffle objects after query? -


As far as I can detect, there is no easy random query function in parse. Is there any way to shuffle things after checking those items?

  query.findObjectsInBackgroundWithBlock {(objects, error) - & gt; If in zero (error == zero) {// Shuffle objects are here? PFObject.pinAllInBackground (objects, withName: "card", block: zero)  

Any ideas? Thanks!

EDIT: I think the problem is at another point. When I add suggestions for shuffling posts (thanks for that), it works like a breeze!

But!

  query.findObjectsInBackgroundWithBlock {(objects, error) - & gt; Zero in zero (error == zero) {println (objects) var shuffled = objects.shuffled () println (shuffled) PFObject.pinAllInBackground (shuffled, withName: "card", block: zero)  

As you can see, I pins the objects in local storage.

On my next scene, I drag this data back to the storage:

  var query = PFQuery (classname: "card") query.fromLocalDatastore () query. FindObjectsInBackgroundWithBlock {(objects, error) - & gt; In zero (zero == zero) {println ("From the local store: \ (objects"))  

And here I have data in the same order because they are saved to the database ... There are no shuffle items.

Is not it weird?

Just take the object and use the shuffle method provided in the objects:

< Pre> var shuffledObjects = shuffle (object)

No comments:

Post a Comment