Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // NSArray+Chunky.h
- //
- // Created by Christopher Miller on 8/19/11.
- // Copyright 2011 FSDEV. All rights reserved.
- //
- #import <Foundation/Foundation.h>
- @interface NSArray (Chunky)
- /**
- * YOU GOT 'TA CHUNKIFY!!! JUST LIKE A BOW-LEGGÈD MONKEY!!! YOU GOT 'TA CHUNKIFY!!! NSAAAAAAARRRRAAAAYAH!
- *
- * Takes sth like this:
- *
- * ( 1, 2, 3, 4, 5, 6, 7, 8, 9 )
- *
- * and then a call like this:
- *
- * [myArray chunkifyWithMaxSize:3];
- *
- * will return sth like this:
- *
- * ( ( 1, 2, 3 ), ( 4, 5, 6 ), ( 7, 8, 9 ))
- */
- - (NSArray *)chunkifyWithMaxSize:(NSUInteger)size;
- @end
- //
- // NSArray+Chunky.m
- //
- // Created by Christopher Miller on 8/19/11.
- // Copyright 2011 FSDEV. All rights reserved.
- //
- #import "NSArray+Chunky.h"
- @implementation NSArray (Chunky)
- - (NSArray *)chunkifyWithMaxSize:(NSUInteger)size
- {
- NSAutoreleasePool * pool0 = [[NSAutoreleasePool alloc] init];
- NSMutableArray * chunks = [[NSMutableArray alloc] init];
- NSMutableArray * chunk = [NSMutableArray array];
- for (id object in self) {
- if ([chunk count] == size) {
- [chunks addObject:chunk];
- chunk = [NSMutableArray array];
- }
- [chunk addObject:object];
- }
- if ([chunk count] > 0)
- [chunks addObject:chunk];
- [pool0 release];
- return [NSArray arrayWithArray:[chunks autorelease]];
- }
- @end
Add Comment
Please, Sign In to add comment