Created
August 19, 2011 16:49
-
-
Save mysteriouspants/1157309 to your computer and use it in GitHub Desktop.
Sign that I'm Going Nuts. I'm putting corrupted lyrics to Tower of Power songs into my source code. With diacriticals.
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+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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'd go with something like this: