-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathNSArray+select.m
More file actions
36 lines (30 loc) · 791 Bytes
/
NSArray+select.m
File metadata and controls
36 lines (30 loc) · 791 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#import "YOLO.ph"
#import <objc/runtime.h>
@implementation NSArray (YOLOSelect)
// The blockToUse variable is necessary or: EXC_BAD_ACCESS
#define YOLOSelectReject(logic) \
if (!input) return @[]; \
BOOL (^blockToUse)(); \
if (YOLOIsClass(input)) { \
blockToUse = ^(id o){ \
return [o isKindOfClass:input]; \
}; \
} else \
blockToUse = input;\
id selected[self.count]; \
int ii = 0; \
for (id o in self) \
if (logic blockToUse(o)) \
selected[ii++] = o; \
return [NSArray arrayWithObjects:selected count:ii]
- (NSArray *(^)(id))select {
return ^(id input) {
YOLOSelectReject(!!);
};
}
- (NSArray *(^)(id))reject {
return ^(id input) {
YOLOSelectReject(!);
};
}
@end