
Untitled
By: a guest on
Dec 19th, 2012 | syntax:
Objective C | size: 0.98 KB | hits: 32 | expires: Never
NSMutableArray *tableSections = [[NSMutableArray alloc] init];
NSMutableArray *sectionData = [[NSMutableArray alloc] init];
NSMutableArray *yourCustomDataObject;
int sectionIndex;
// Pseudo-code to create data structure
for(id episode in episodes) {
sectionIndex = [[episode objectForKey:@"Season"] intValue];
yourCustomDataObject = [[NSMutableArray alloc] initWithObjects:episode, nil];
// Do index check first to insure no out of bounds
if(sectionIndex <= [tableSections count]) { // tableSections will always count 0
sectionData = [tableSections objectAtIndex:sectionIndex];
}
// Create the new section array if there isn't one for the current section
if(!sectionData) {
sectionData = [NSMutableArray new];
[tableSections insertObject:sectionData atIndex:sectionIndex];
}
[sectionData addObject:yourCustomDataObject];
}
NSLog(@"%d %d", [tableSections count], [sectionData count]);