-
Notifications
You must be signed in to change notification settings - Fork 0
/
NSMutableArrayExtension.m
45 lines (34 loc) · 1.02 KB
/
NSMutableArrayExtension.m
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
//
// NSMutableArrayExtension.m
//
// Licensed by ruralcoder.com under the
// Creative Commons Attribution-ShareAlike 3.0 Unported License
#import "NSMutableArrayExtension.h"
@implementation NSMutableArray (Extension)
- (void)moveObjectAtIndexPath:(NSUInteger)fromIndex toIndex:(NSUInteger)toIndex
{
if (toIndex == fromIndex)
return;
id object = [[self objectAtIndex:fromIndex] retain];
[self removeObjectAtIndex:fromIndex];
if (toIndex >= [self count])
[self addObject:object];
else
[self insertObject:object atIndex:toIndex];
[object release];
}
- (NSUInteger)indexOfCaseInsensitiveString:(NSString *)aString {
NSUInteger index = 0;
for (NSString *object in self) {
if ([object caseInsensitiveCompare:aString] == NSOrderedSame) {
return index;
}
index++;
}
return NSNotFound;
}
- (BOOL) containsInsensitiveString:(NSString *)aString
{
return ([self indexOfCaseInsensitiveString:aString] != NSNotFound);
}
@end