-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCRL2DArray.m
75 lines (67 loc) · 1.79 KB
/
CRL2DArray.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
//
// CRLTwoDArray.m
// JewelnJewels
//
// Created by tGilani on 20/11/2012.
//
//
#import "CRL2DArray.h"
@interface CRL2DArray ()
{
int capacity;
}
@property (nonatomic, retain) NSMutableArray *outerArray;
@end
@implementation CRL2DArray
@synthesize outerArray;
- (id) initWithRows:(int)x columns:(int)y
{
if (self = [super init])
{
capacity = y;
self.outerArray = [NSMutableArray array];
for (int i = 0; i < x; i++) {
NSMutableArray *innerArray = [NSMutableArray array];
for (int j = 0; j < y; j++) {
[innerArray addObject:kCRL2DArrayEmptyKey];
}
[self.outerArray addObject:innerArray];
}
}
return self;
}
- (BOOL) insertObject:(id)data atRow:(int)x column:(int)y
{
if (x < outerArray.count) {
NSMutableArray *array = [outerArray objectAtIndex:x];
if (y < capacity) {
if (data == nil)
[array replaceObjectAtIndex:y withObject:kCRL2DArrayEmptyKey];
else
[array replaceObjectAtIndex:y withObject:data];
return YES;
}
}
[NSException raise:@"Index out of Bounds" format:@"The Indices Provided were Incorrect %i, %i", x,y];
return NO;
}
- (id) objectAtRow:(int)x column:(int)y
{
if (x < outerArray.count) {
NSMutableArray *array = [outerArray objectAtIndex:x];
if (y < capacity) {
id data = (id)[array objectAtIndex:y];
if ([data isKindOfClass:[NSString class]])
return nil;
else
return data;
}
}
[NSException raise:@"Index out of Bounds" format:@"The Indices Provided were Incorrect %i, %i", x,y];
return nil;
}
- (void) removeAllObjects
{
[self.outerArray removeAllObjects];
}
@end