Created
August 16, 2010 13:40
-
-
Save alexeckermann/526955 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int (^minusOne)(int); | |
minusOne = ^(int myNumber) { | |
return myNumber - 1; | |
}; | |
NSLog(@"%d", minusOne(3)); // Will print: 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; | |
NSLog(@"Block Predicate Arrays ======"); | |
NSLog(@"Dates: %@", otherDates); | |
NSLog(@"Future Dates: %@", futureDates); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
These files are apart of a tutorial on AlexEckermann.com |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NSArray *fruits = [NSArray arrayWithObjects:@"Apple", @"Crabapple", @"Watermelon", @"Lemon", @"Raspberry", @"Rockmelon", @"Orange", @"Lime", @"Grape", @"Kiwifruit", @"Bitter Orange", @"Manderin", nil]; | |
NSPredicate *findMelons = [NSPredicate predicateWithFormat:@"SELF contains[cd] 'melon'"]; | |
NSArray *melons = [fruits filteredArrayUsingPredicate:findMelons]; | |
NSPredicate *findApple = [NSPredicate predicateWithFormat:@"SELF beginswith 'Apple'"]; | |
NSArray *apples = [fruits filteredArrayUsingPredicate:findApple]; | |
NSPredicate *findRNotMelons = [NSPredicate predicateWithFormat:@"SELF beginswith 'R' AND NOT SELF contains[cd] 'melon'"]; | |
NSArray *rNotMelons = [fruits filteredArrayUsingPredicate:findRNotMelons]; | |
NSLog(@"Fruits: %@", fruits); | |
NSLog(@"Melons: %@", melons); | |
NSLog(@"Apples: %@", apples); | |
NSLog(@"RNotMelons: %@", rNotMelons); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment