i am newbie here in iOS and Parse Framework i want to fetch data from my Parse table from PFQuery like as
NSUInteger limit = 1500;
PFQuery *query = [PFQuery queryWithClassName:@"MapInfo"];
[query setLimit: limit];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error)
{
if (!error) {
NSLog(@"Successfully retrieved: %@", objects);
} else {
NSString *errorString = [[error userInfo] objectForKey:@"error"];
NSLog(@"Error: %@", errorString);
}
}];
it is Working as i want but it is give me only 1000 objects i want here to fetch all my table data it contain unto 2000 object and it will increment as day by day please help me for this.
For this Now i write a code like this but it is Only Give me 1000 Objects only
NSMutableArray *allObjects = [NSMutableArray array];
NSUInteger limit = 0;
__block NSUInteger skip = 0;
PFQuery *query = [PFQuery queryWithClassName:@"MapInfo"];
[query setLimit: limit];
[query setSkip: skip];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
[allObjects addObjectsFromArray:objects];
if (objects.count == limit) {
skip += limit;
[query setSkip: skip];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
NSLog(@"Array %@",objects);
}];
}
} else {
NSLog(@"Error: %@ %@", error, [error userInfo]);
}
}];
thanks.
https://parse.com/questions/fetch-all-data-in-a-table-using-pfquery
You can use the skip and limit parameter to paginate through all objects in the table by adding the value of limit to skip until the query returns an amount of objects that is less than limit.
This is a simple recursive solution to retrieve all the objects from a class using blocks.
Here is how you initially call it.
Here is the method.
}
I've tested this with less than 1000 objects, 1000 objects, and more than 1000 objects and it works perfectly.
Be cautious of how many objects you're grabbing though because this will grab all of them and if you're working with a large data set that might be an issue in terms of memory very quickly.
I believe there is a query limit on the number of objects that can be fetched. What I would do is query make two queries for the same thing but for the second query, do something like this
[query setSkip1000];
you can skip the first 1000 objects in the first query and grab the next 1000. Make your array an
NSMutableArray
and inside each block do this[self.myArray addObjects:objects];
instead ofself.myArray = objects;
that way you are overwriting the objects in your array.Edit
Instead of 2 separate queries you can also do this