Saqib Saud
Saqib Saud

Reputation: 2795

Using NSFetchRequest how to get last X items and continue upward

Im using NSFetchRequest in NSFetchedResultsController to fetch data, sorted based on date

  NSSortDescriptor *sortDescriptor=[[NSSortDescriptor alloc] initWithKey:@"timeStamp" ascending:YES];

As you can see it sorts the results based on timestamp and I can get ascending and descending results.

but what i want is, lets say if i have 1-100 rows. In first query I want to have 95-100 results, then 90-100 , then 85-100 so on...

Thanks

Upvotes: 0

Views: 195

Answers (2)

Saqib Saud
Saqib Saud

Reputation: 2795

fetchOffset and fetchLimit will help you to paginate your results, this is not my problem.

changing NSSortDescriptor to ascend or descend will show results like this 10-to-6 then in second iteration 10-to-1 Or 1-to-5 and in second iteration 1-to-10

what I wanted was, for instance, if i have rows 1-to-10 i wanted to show rows 6-to-10 in first iteration and 1-to-10 in second iteration in same order.

You can achieve this results by using NSPredicate

NSPredicate * predicate = [NSPredicate predicateWithFormat:@"timeStamp >=%@",[[NSDate date] dateBySubtractingDays:self.page]];

Upvotes: 0

Matthias Bauch
Matthias Bauch

Reputation: 90117

Set fetchOffset and fetchLimit of your NSFetchRequest.

Upvotes: 2

Related Questions