summaryrefslogtreecommitdiffstats
path: root/Classes/SectionDictionary.m
diff options
context:
space:
mode:
Diffstat (limited to 'Classes/SectionDictionary.m')
-rw-r--r--Classes/SectionDictionary.m33
1 files changed, 27 insertions, 6 deletions
diff --git a/Classes/SectionDictionary.m b/Classes/SectionDictionary.m
index b183725..9124714 100644
--- a/Classes/SectionDictionary.m
+++ b/Classes/SectionDictionary.m
@@ -15,6 +15,7 @@
- (SectionDictionary *) init {
index = 0;
+ sortedKeys = [[[NSMutableArray alloc] init] retain];
indexMap = [[[NSMutableDictionary alloc] init] retain];
theRealDictionary = [[[NSMutableDictionary alloc] init] retain];
[super init];
@@ -27,22 +28,39 @@
return theRealDictionary;
}
+- (void) sortKeys {
+ [sortedKeys sortUsingComparator:(NSComparator)^(id obj1, id obj2){
+ return [obj2 compare:obj1];
+ }];
+}
+
- (void) setObject:(id)anObject forKey:(id)aKey {
- [indexMap setObject:aKey forKey:[NSString stringWithFormat:@"%d", index]];
- index++;
+// [indexMap setObject:aKey forKey:[NSString stringWithFormat:@"%d", index]];
+// index++;
[theRealDictionary setObject:anObject forKey:aKey];
+
+ [sortedKeys addObject:aKey];
+ [self sortKeys];
+}
+
+- (NSArray *) allIndices {
+ NSLog(@"%@ %@", [indexMap allKeys], [indexMap allValues]);
+ return [indexMap allKeys];
}
// lets you push objects into sections without worry about storage
- (void) appendObject:(id)anObject forKey:(id)aKey {
NSMutableArray *store = [theRealDictionary objectForKey:aKey];
if (store == nil) {
- [indexMap setObject:aKey forKey:[NSString stringWithFormat:@"%d", index]];
- index++;
+// [indexMap setObject:aKey forKey:[NSString stringWithFormat:@"%d", index]];
+// index++;
NSMutableArray *store = [[[NSMutableArray alloc] init] autorelease];
[store addObject:anObject];
[theRealDictionary setObject:store forKey:aKey];
+
+ [sortedKeys addObject:aKey];
+ [self sortKeys];
}
else [store addObject:anObject];
@@ -50,14 +68,17 @@
}
- (id) objectForIndex:(NSInteger)i {
- return [theRealDictionary objectForKey:[indexMap objectForKey:[NSString stringWithFormat:@"%d", i]]];
+ return [theRealDictionary objectForKey:[sortedKeys objectAtIndex:i]];
+ //return [theRealDictionary objectForKey:[indexMap objectForKey:[NSString stringWithFormat:@"%d", i]]];
}
- (NSString *) keyForIndex:(NSInteger)i {
- return [indexMap objectForKey:[NSString stringWithFormat:@"%d", i]];
+ return [sortedKeys objectAtIndex:i];
+ //return [indexMap objectForKey:[NSString stringWithFormat:@"%d", i]];
}
- (void) dealloc {
+ [sortedKeys release];
[theRealDictionary release];
[indexMap release];
[super dealloc];