Backendless Support
 
Waiting for user's response

Sync object retrieval on Backendless 4.0

I need to retrieve objects synchronously using Backendless 4.0. How can I prepare the Data Query Builder next page synchronously using iOS SDK?

Best Answer
photo

Please, check this:

  1. -(void)paging:(DataQueryBuilder *)queryBuilder {
  2. NSArray *people = [[backendless.data of:[Person class]] find:queryBuilder];
  3. if (people.count != 0) {
  4. NSLog(@"Loaded %d people in the current page", (int)people.count);
  5. for (Person *person in people) {
  6. NSLog(@"%@, age %i", person.name, (int)person.age);
  7. }
  8. [self paging:[queryBuilder prepareNextPage]];
  9. }
  10. else {
  11. NSLog(@"Reached the end of collection");
  12. }
  13. }

Regards, Olga

Leave a Comment

Comments (8)

photo
1

Did you see the doc on data paging?

photo
1

Yes, I saw it, but I didn't find out how to access next page using the sync method.

photo
1

The nextPage method simply recalculates the offset. You would need to use the find method to fetch data.

photo
1

Please, check this:

  1. -(void)paging:(DataQueryBuilder *)queryBuilder {
  2. NSArray *people = [[backendless.data of:[Person class]] find:queryBuilder];
  3. if (people.count != 0) {
  4. NSLog(@"Loaded %d people in the current page", (int)people.count);
  5. for (Person *person in people) {
  6. NSLog(@"%@, age %i", person.name, (int)person.age);
  7. }
  8. [self paging:[queryBuilder prepareNextPage]];
  9. }
  10. else {
  11. NSLog(@"Reached the end of collection");
  12. }
  13. }

Regards, Olga

photo
1

Well, but now it obligates us to increase the number of requisitions to the database once I need to use a recursive method.

photo
1

Whether you use the sync approach or the async one, the number of database requests would be the same.

photo
1

Yes, but it will be greater than the Backendless 3.0 API

photo
1

This is not right. The prepareNextPage method is not an API call, it merely does the following:

  1. offset += pageSize;

photo