/
MusicalTablesSection.m
90 lines (68 loc) · 2.26 KB
/
MusicalTablesSection.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
//
// MusicalTablesSection.m
// MusicalTables
//
// Created by Tim Cinel on 2011-11-17.
// Copyright (c) 2011 __MyCompanyName__. All rights reserved.
//
#import "MusicalTablesSection.h"
#import "MusicalTables.h"
@implementation MusicalTablesSection
@synthesize identifier = _identifier;
@synthesize rows = _rows;
#pragma mark - NSObject
- (id)init {
return [self initWithIdentifier:nil rows:nil];
}
- (id)initWithIdentifier:(NSString *)identifierOrNil rows:(NSMutableArray *)rowsOrNil {
if (nil != (self = [super init])) {
_identifier = identifierOrNil;
_rows = (nil != rowsOrNil ? [rowsOrNil retain] : [[NSMutableArray alloc] init]);
}
return self;
}
+ (id)musicalTablesSectionWithIdentifier:(NSString *)identifierOrNil rows:(NSMutableArray *)rowsOrNil {
return [[[MusicalTablesSection alloc] initWithIdentifier:identifierOrNil rows:rowsOrNil] autorelease];
}
- (void)dealloc {
self.identifier = nil;
self.rows = nil;
[super dealloc];
}
- (BOOL)isEqual:(id)object {
if ([object isKindOfClass:[MusicalTablesSection class]])
return [self.identifier isEqualToString:[(MusicalTablesSection *)object identifier]];
return NO;
}
#pragma mark - NSMutableArray Mimic
- (NSUInteger)count {
NSLog(@"About to count: %@", self.rows);
return self.rows.count;
}
- (id)objectAtIndex:(NSUInteger)index {
return [self.rows objectAtIndex:index];
}
- (void)addObject:(id)anObject {
[self.rows addObject:anObject];
}
- (void)insertObject:(id)anObject atIndex:(NSUInteger)index {
[self.rows insertObject:anObject atIndex:index];
}
- (void)removeLastObject {
[self.rows removeLastObject];
}
- (void)removeObjectAtIndex:(NSUInteger)index {
[self.rows removeObjectAtIndex:index];
}
- (void)replaceObjectAtIndex:(NSUInteger)index withObject:(id)anObject {
[self.rows replaceObjectAtIndex:index withObject:anObject];
}
#pragma NSCopying
- (id)copyWithZone:(NSZone *)zone {
//create new MusicalTablesSection
MusicalTablesSection *newSection = [[MusicalTablesSection allocWithZone:zone] initWithIdentifier:self.identifier rows:nil];
//create new rows (with same contents)
newSection.rows = [[[NSMutableArray allocWithZone:nil] initWithArray:self.rows] autorelease];
return newSection;
}
@end