Return to Snippet

Revision: 44418
at April 11, 2011 17:08 by magickaito


Initial Code
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"dd/mm/yyyy"];

NSDate *referenceDate = [dateFormatter dateFromString:@"16/08/2010"];

NSArray *otherDates = [NSArray arrayWithObjects:@"12/08/2010", @"25/10/1990", @"30/08/2010", @"25/12/2010", nil];

NSPredicate *findFutureDates = [NSPredicate predicateWithBlock: ^BOOL(id obj, NSDictionary *bind){
	return [referenceDate earlierDate: [dateFormatter dateFromString: (NSString *)obj]] == referenceDate;
}];

NSArray *futureDates = [otherDates filteredArrayUsingPredicate: findFutureDates];

[dateFormatter release];

Initial URL


Initial Description


Initial Title
Example of filtering an array using predicateWithBlock

Initial Tags


Initial Language
Objective C