Guest User

Untitled

a guest
Jan 23rd, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. //
  2. // NSArray+Chunky.h
  3. //
  4. // Created by Christopher Miller on 8/19/11.
  5. // Copyright 2011 FSDEV. All rights reserved.
  6. //
  7.  
  8. #import <Foundation/Foundation.h>
  9.  
  10. @interface NSArray (Chunky)
  11.  
  12. /**
  13. * YOU GOT 'TA CHUNKIFY!!! JUST LIKE A BOW-LEGGÈD MONKEY!!! YOU GOT 'TA CHUNKIFY!!! NSAAAAAAARRRRAAAAYAH!
  14. *
  15. * Takes sth like this:
  16. *
  17. * ( 1, 2, 3, 4, 5, 6, 7, 8, 9 )
  18. *
  19. * and then a call like this:
  20. *
  21. * [myArray chunkifyWithMaxSize:3];
  22. *
  23. * will return sth like this:
  24. *
  25. * ( ( 1, 2, 3 ), ( 4, 5, 6 ), ( 7, 8, 9 ))
  26. */
  27. - (NSArray *)chunkifyWithMaxSize:(NSUInteger)size;
  28.  
  29. @end
  30.  
  31. //
  32. // NSArray+Chunky.m
  33. //
  34. // Created by Christopher Miller on 8/19/11.
  35. // Copyright 2011 FSDEV. All rights reserved.
  36. //
  37.  
  38. #import "NSArray+Chunky.h"
  39.  
  40. @implementation NSArray (Chunky)
  41.  
  42. - (NSArray *)chunkifyWithMaxSize:(NSUInteger)size
  43. {
  44. NSAutoreleasePool * pool0 = [[NSAutoreleasePool alloc] init];
  45. NSMutableArray * chunks = [[NSMutableArray alloc] init];
  46. NSMutableArray * chunk = [NSMutableArray array];
  47. for (id object in self) {
  48. if ([chunk count] == size) {
  49. [chunks addObject:chunk];
  50. chunk = [NSMutableArray array];
  51. }
  52. [chunk addObject:object];
  53. }
  54. if ([chunk count] > 0)
  55. [chunks addObject:chunk];
  56. [pool0 release];
  57. return [NSArray arrayWithArray:[chunks autorelease]];
  58. }
  59.  
  60. @end
Add Comment
Please, Sign In to add comment