self.list = @[@"1", @"2", @"3", @"4", @"5", @"6", @"3"];
[self.list bk_each:^(id obj) {
NSLog(@"bk_each: %@", obj);
}];
NSArray *bk_map = [self.list bk_map:^id(id obj) {
return [NSString stringWithFormat:@"%@.png", obj];
}];
NSLog(@"%@", bk_map);
NSString *bk_reduceStr = [self.list bk_reduce:@"A" withBlock:^id(id sum, id obj) {
return [sum stringByAppendingString:obj];
}];
NSLog(@"bk_reduceStr: %@", bk_reduceStr);
NSInteger bk_reduceInteger = [self.list bk_reduceInteger:2 withBlock:^NSInteger(NSInteger result, id obj) {
return result + [obj integerValue];
}];
NSLog(@"bk_reduceInteger: %ld", bk_reduceInteger);
NSLog(@"bk_any: %d", [self.list bk_any:^BOOL(id obj) {
return [obj isEqualToString:@"7"];
}]);
[self.list bk_apply:^(id obj) {
NSLog(@"bk_apply: %@", obj);
}];
NSLog(@"bk_any: %d", [self.list bk_any:^BOOL(id obj) {
return [obj isEqualToString:@"4"];
}]);
NSLog(@"bk_none: %d", [self.list bk_none:^BOOL(id obj) {
return [obj isEqualToString:@"4"];
}]);
NSLog(@"bk_all: %d", [self.list bk_all:^BOOL(id obj) {
return [obj isEqualToString:@"4"];
}]);
NSArray *arr1 = @[@"1", @"2", @"3", @"4", @"5", @"6", @"3"];
NSArray *arr2 = @[@"1", @"2", @"3", @"4", @"5", @"6", @"4"];
NSLog(@"%d", [self.list bk_corresponds:arr1 withBlock:^BOOL(id obj1, id obj2) {
return [obj1 isEqual:obj2];
}]);
NSLog(@"%d", [self.list bk_corresponds:arr2 withBlock:^BOOL(id obj1, id obj2) {
return [obj1 isEqual:obj2];
}]);
NSArray *selArr = [self.list bk_select:^BOOL(id obj) {
return [obj isEqualToString:@"3"];
}];
NSLog(@"bk_select: %@", selArr);
NSString *bk_match = [self.list bk_match:^BOOL(id obj) {
return [obj isEqualToString:@"3"];
}];
NSLog(@"bk_match: %@", bk_match);
NSArray *bk_reject = [self.list bk_reject:^BOOL(id obj) {
return [obj isEqualToString:@"3"];
}];
NSLog(@"bk_reject: %@", bk_reject);
NSArray+BlocksKit
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 版本记录 前言 NSArray是我们经常使用的一个类,但是苹果的API很多用起来不是那么方便,需要根据我们特殊需求...