Deleting old cache and data via date/time limit


#1

So here’s a personal challenge I’ve been going through that I would love help on. Alongside the finalized version of this project (using all three versions of the stored data) I would like to be able to remove all items that are before a certain time period. Say (hypothetically speaking) the feed for this application provided you with posts from yesterday. I don’t want those posts to be stored anywhere in my application and want to ensure that ONLY the posts created today display in the application. Does anyone know how to go about this? I’ve been attempting to use the following snippet of code I wrote to cut out the older feed/items. Unfortunately, placement of this code is becoming a hassle and I can’t seem to grab everything. The real problem takes into effect when trying to remove the items from the tableview via animations (consistent out of bounds errors).

[code] if ([[[channelCopy items] lastObject] class] == [BNRItem class]) {

            NSDate *cutOffDate = [[NSDate date] dateByAddingTimeInterval:kfeedCutOff*24*60*60];
            NSLog(@"Response: %d",[[[[channelCopy items] lastObject] publishDate] compare:cutOffDate]);
            while (([[channelCopy items]lastObject] != NULL) && ([[[[channelCopy items] lastObject] publishDate] compare:cutOffDate] == NSOrderedAscending)) {
                NSLog(@"Removed: %@", [[channelCopy items] lastObject]);
                [[channelCopy items] removeLastObject];
            }
        }

[/code]

within fethEntries I’ve attempted adding in the following snippets:

            int itemDelta = newItemCount - currentItemCount;
            if (itemDelta > 0) {
                NSMutableArray *rows = [NSMutableArray array];
                for (int i = 0; i < itemDelta; i++) {
                    NSIndexPath *ip = [NSIndexPath indexPathForRow:i inSection:0];
                    [rows addObject:ip];
                }
                
                [[self tableView] insertRowsAtIndexPaths:rows withRowAnimation:UITableViewRowAnimationTop];
            }
            else if (itemDelta < 0){ //Removes outdated cells from the tableView
                NSLog(@"We have a problem");
               NSMutableArray *rows = [NSMutableArray array];
                for (int i = 0; i > itemDelta; i--) {
                    NSIndexPath *ip = [NSIndexPath indexPathForRow:(i + currentItemCount) inSection:0];
                    [rows addObject:ip];
                }
                [[self tableView] deleteRowsAtIndexPaths:rows withRowAnimation:UITableViewRowAnimationBottom];
            }
            
        }

I have heard that tablViews NEED at least one row inserted if you remove at the zero mark… which I’ve tried doing as well. Any thoughts?