Commits

Daniel Tull committed 8b4ea24

Added a method to split an NSArray into multiple NSArrays.

  • Participants
  • Parent commits 3846d9c

Comments (0)

Files changed (2)

DTFoundation/NSArray+DTExtras.h

 - (NSArray *)subarrayWithObjectsOfClass:(Class)aClass;
 
 - (BOOL)containsObjectOfClass:(Class)aClass;
+
+- (NSArray *)dtSplitArrayIntoArraysWithCount:(NSInteger)aCount;
 @end

DTFoundation/NSArray+DTExtras.m

 	return NO;
 }
 
+- (NSArray *)dtSplitArrayIntoArraysWithCount:(NSInteger)aCount {
+	
+	NSInteger c = [self count];
+	
+	NSMutableArray *splitArrays = [[NSMutableArray alloc] init];
+	
+	NSRange range = NSMakeRange(0, aCount);
+	
+	while (c > 0) {
+		
+		if (c < aCount) range.length = c;
+		
+		NSArray *splitArray = [self subarrayWithRange:range];
+		[splitArrays addObject:splitArray];
+		
+		range.location += range.length;
+		
+		c - aCount;
+	}
+	
+	NSArray *returnArray = [splitArrays copy];
+	[splitArrays release];
+	return [returnArray autorelease];
+}
+
 @end