Add this method in your class
- (BOOL)isDate:(NSDate *)startDate earlierThanDate:(NSDate *)endDate
{
if ([startDate compare:endDate] == NSOrderedAscending) {
return YES;
} else if ([startDate compare:endDate] == NSOrderedSame) {
return YES;
} else {
return NO;
}
}
Then before adding object to the array,check whether it is a future date or not with this method
- (void)requestFinished:(ASIHTTPRequest *)request {
[_queue addOperationWithBlock:^{
NSError *error;
GDataXMLDocument *doc = [[GDataXMLDocument alloc] initWithData:[request responseData]
options:0 error:&error];
if (doc == nil) {
NSLog(@"Failed to parse %@", request.url);
} else {
NSMutableArray *entries = [NSMutableArray array];
[self parseFeed:doc.rootElement entries:entries];
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
for (RSSEntry *entry in entries) {
if ([self isDate:[NSDate date] earlierThanDate:entry.articleDate]) {
int insertIdx = [_allEntries indexForInsertingObject:entry sortedUsingBlock:^(id a, id b) {
RSSEntry *entry1 = (RSSEntry *) a;
RSSEntry *entry2 = (RSSEntry *) b;
return [entry1.articleDate compare:entry2.articleDate];
}];
[_allEntries insertObject:entry atIndex:insertIdx];
[self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:insertIdx inSection:0]]
withRowAnimation:UITableViewRowAnimationRight];
}
}
}];
}
}];
[self.refreshControl endRefreshing];
}