maxgoedjen / NSArray-Comprehension

Python-like array comprehensions for Objective-C

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

NSArray-Comprehension

Python-like array comprehensions for Objective-C

Examples

Square list of NSNumbers

NSArray *test = @[@1, @2, @3, @4, @5];
NSArray *comp = [test arrayWithComprehension:^id(id obj) {
	return @([obj intValue] * [obj intValue]);
}];

Filtering is also supported

NSArray *comp = [test arrayWithComprehension:^id(id obj) {
	return @([obj intValue] * [obj intValue]);
} ifCondition:^BOOL(id obj) {
	return ([obj intValue] % 2 == 0);
}];

About

Python-like array comprehensions for Objective-C


Languages

Language:Objective-C 100.0%