-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNSArray+Utilities.mm
52 lines (39 loc) · 987 Bytes
/
NSArray+Utilities.mm
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//
// author: fabrice truillot de chambrier
//
// © 2009-2015, men in silicium sàrl
//
#import "OS/NSArray+Utilities.h"
@implementation NSArray (Utilities)
- (BOOL) isMutable
{
return [self isMutableArray];
}
- (BOOL) isMutableArray
{
return [self respondsToSelector: @selector(addObject:)];
}
- (NSIndexSet*) indexesOfObjects: (NSArray*) objects
{
return [self indexesOfObjectsPassingTest: ^ BOOL ( id object, NSUInteger index, BOOL* stop )
{
return [objects containsObject: object];
}];
}
@end
@implementation NSMutableArray (Utilities)
- (void) intersectArray: (NSArray*) otherArray
{
NSIndexSet* indexes = [self indexesOfObjectsPassingTest: ^ BOOL ( id object, NSUInteger index, BOOL* stop )
{
return not [otherArray containsObject: object];
}];
[self removeObjectsAtIndexes: indexes];
}
- (void) unionArray: (NSArray*) otherArray
{
for ( id object in otherArray ) {
if ( not [self containsObject: object] ) [self addObject: object];
}
}
@end