So I have an Array (NSMutable) of objects and I am trying to filter them by date. Specifically I only want those objects that are less than 7 days old.
Last night I toiled away and got NSPredicate to do the job. And it did a BEAUTIFUL Job in the simulator. So I hook up my iPod touch and click Build and Go. Error, NSPredicate, bla bla bla. hmmmmm......So I start searching online and apparently NSPredicate is available in the simulator, but does NOT work on the actual Device. It is not included as part of the Foundation. Great.
So now I'm stuck, I don't know how else to do it. The Documentation specifically tells you to use NSPredicate to filter an Array. And that's the only suggestion that it gives you. (In hindsight, it also says that it's not available on the phone. lol)
Here is my code:
Are there any suggestions?
Sorry about the weird formatting, it's my first post.
Last night I toiled away and got NSPredicate to do the job. And it did a BEAUTIFUL Job in the simulator. So I hook up my iPod touch and click Build and Go. Error, NSPredicate, bla bla bla. hmmmmm......So I start searching online and apparently NSPredicate is available in the simulator, but does NOT work on the actual Device. It is not included as part of the Foundation. Great.
So now I'm stuck, I don't know how else to do it. The Documentation specifically tells you to use NSPredicate to filter an Array. And that's the only suggestion that it gives you. (In hindsight, it also says that it's not available on the phone. lol)
Here is my code:
Code:
*NSDate nowDate = NSDate date;
// Take the Current date and find the time since 1970
NSTimeInterval now = nowDate timeIntervalSince1970;
// Take the time since 1970 and subtract the number of seconds in a week.
NSTimeInterval weekAgo = (now - 604800);
// Create the Predicate to do the Filtering.
*NSPredicate predicate = [NSPredicate predicateWithFormat:@"startDateTime >= %@", NSDate dateWithTimeIntervalSince1970: weekAgo];
// Load a New array with all of the sessions.
*NSMutableArray filteredArray = [NSMutableArray alloc initWithArray:appDelegate sessions];
// Fiter that new Array.
*filteredArray filterUsingPredicate:predicate; *
Are there any suggestions?
Sorry about the weird formatting, it's my first post.