Created
August 26, 2011 19:36
-
-
Save beelsebob/1174235 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| - (NSArray *)chunkifyWithMaxSize:(NSUInteger)size | |
| { | |
| NSArray *r; | |
| NSUInteger c = [self count]; | |
| NSUInteger numFullChunks = / size; | |
| NSUInteger lastChunkPosition = size * numFullChunks; | |
| @autoreleasepool | |
| { | |
| NSMutableArray *result = [[NSMutableArray alloc] initWithCapacity:numFullChunks + 1]; | |
| for (NSUInteger chunk = 0; chunk < numFullChunks; chunk++) | |
| { | |
| [result addObject:[self subArrayWithRange:NSMakeRange(chunk * size, size)]]; | |
| } | |
| if (lastChunkPosition < c) | |
| { | |
| [result addObject:[self subArrayWithRange:NSMakeRange(lastChunkPosition, c - lastChunkPosition)]; | |
| } | |
| r = [[result copy] autorelease]; | |
| [result release]; | |
| } | |
| return r; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment