0

I am currently trying to make requests with Parse but I would like to start from "a random point" in database.

Since my app sorts automatically feed results in a "fixed way", users will always get the same results in their feed but I would like to make it more random. So, every time the user reloads his feed, he would get different results since there is a large number of users.

I feel like the first requests are the ones at the bottom of the database table (in Parse).

So,aren't there any way to give it a "starting point" in database?

Here's the code:

   let query = PFQuery(className: "_User")

   //query.startingIndex = 4 for e.g ??

   query.findObjectsInBackground { (objects, error) in


   }

I would be glad to know someone can help me out

rmaddy
  • 314,917
  • 42
  • 532
  • 579
clmrie
  • 78
  • 7
  • 1
    You can use the `query.skip = someNumber` option. Reference: https://docs.parseplatform.org/ios/guide/#query-constraints – Davi Macêdo Sep 09 '19 at 01:43

1 Answers1

0

Maybe there is no way to get random data from Parse Server. But you can try it in these ways:

  • You can retrieve data by creation date. It will give you the latest data first, so it looks like the data is changing. For this, you can add the order query:

    query.order(byDescending: "createdAt")

  • Or, after retrieving data you can first shuffle the list and then show. Here is the link for shuffle an array: How do I shuffle an array in Swift?

Nomanur
  • 266
  • 5
  • 7