how do I ask core data to fetch me the last 30 elements entered or alternatively the elements entered within a month of today?
Asked
Active
Viewed 459 times
1 Answers
1
To fetch a certain number of records, use qualification like [fetchRequest setFetchLimit:30]
in combination with NSPredicate instance you desired.
To retrieve elements within a range of time, you need first calculate the beginning and the end NSDate instances of the period you want, then code your predicate instance like:
NSPredicate *predicate = [NSPredicate predicateWithFormat:
@"(date >= %@) AND (date <= %@)", startDate, endDate];
-
Thanks I'll probably use the second option but wouldn't the [fetchRequest setFetchLimit:30] retrieve the first 30 and not the last 30? – Ayrad Jan 29 '12 at 16:41
-
ok I can probably sort in descending order and then do the setFetchLimit – Ayrad Jan 29 '12 at 16:46
-
Yeah. Just as you've figured out. – ZhangChn Jan 29 '12 at 16:52