-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathNSArray+Utils.m
More file actions
64 lines (55 loc) · 1.38 KB
/
NSArray+Utils.m
File metadata and controls
64 lines (55 loc) · 1.38 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
//
// NSArray+Utils.m
//
// Created by Jiva DeVoe on 12/21/11.
// Copyright (c) 2011 Random Ideas, LLC. All rights reserved.
//
#import "NSArray+Utils.h"
@implementation NSArray (Utils)
-(id)firstObject
{
return ([self count] > 0) ? [self objectAtIndex:0] : nil;
}
+(id)arrayWithUniqueObjectsFromArray:(NSMutableArray *)otherArray;
{
NSMutableArray *ret = [NSMutableArray array];
for(id item in otherArray)
{
if(![ret containsObject:item])
[ret addObject:item];
}
return ret;
}
+(id)arrayWithCount:(int)count string:(NSString *)templateObject;
{
NSMutableArray *ret = [NSMutableArray array];
for(int n = 0; n < count; ++n)
{
[ret addObject:templateObject];
}
return ret;
}
-(NSArray *)twoDimensionalArrayWithDepth:(NSInteger)inDepth;
{
NSMutableArray *ret = [NSMutableArray array];
NSMutableArray *row = [NSMutableArray array];
for(NSInteger n = 0; n < [self count]; ++n)
{
[row addObject:[self objectAtIndex:n]];
if(((n+1) % inDepth) == 0)
{
[ret addObject:row];
row = [NSMutableArray array];
}
}
if([row count] > 0 && [row count] < inDepth)
{
for(NSUInteger n = [row count]; n < inDepth; ++n)
{
[row addObject:[NSNull null]];
}
[ret addObject:row];
}
return ret;
}
@end