365Cocoa

A snippet of Objective-C code per day, 365 days long.
Written by Pieter Omvlee, developer and owner of Bohemian Coding.

Mar 9

Day 11: insertObjectsFromArray:atIndex

Today’s one is a simple one since I’ve had a busy day and frankly have seen enough Cocoa for the day. Still this can be a handy method and it’s not provided by default in Cocoa. So there we go;

@implementation NSMutableArray (NSArray_365Cocoa)
- (void)insertObjectsFromArray:(NSArray *)array atIndex:(int)index
{
  for (id obj in array)
    [self insertObject:obj atIndex:index++];
}
@end