Skip to content

Instantly share code, notes, and snippets.

@stevestreza
Created September 13, 2009 20:27
Show Gist options
  • Select an option

  • Save stevestreza/186319 to your computer and use it in GitHub Desktop.

Select an option

Save stevestreza/186319 to your computer and use it in GitHub Desktop.
//
// NSArray+ConcurrencyAdditions.h
// ConcurrencyExtensions
//
// Created by Steve Streza on 9/13/09.
// Copyright 2009 __MyCompanyName__. All rights reserved.
//
#import <Foundation/Foundation.h>
typedef NSObject* (^SSPopulator)(NSUInteger index);
@interface NSArray (ConcurrencyAdditions)
+(NSArray *)SS_arrayWithCount:(NSUInteger)count withOptions:(NSEnumerationOptions)options populator:(SSPopulator)populator;
-(id)SS_arrayByAddingCount:(NSUInteger)count withOptions:(NSEnumerationOptions)options populator:(SSPopulator)populator;
-(id)SS_arrayByInsertingCount:(NSUInteger)count atIndex:(NSUInteger)index withOptions:(NSEnumerationOptions)options populator:(SSPopulator)populator;
@end
@interface NSMutableArray (ConcurrencyAdditions)
-(void)SS_addCount:(NSUInteger)count withOptions:(NSEnumerationOptions)options populator:(SSPopulator)populator;
-(void)SS_insertCount:(NSUInteger)count atIndex:(NSUInteger)index withOptions:(NSEnumerationOptions)options populator:(SSPopulator)populator;
@end
-(void)doSomething{
NSArray *myArray = [NSArray SS_arrayWithCount:100
withOptions:NSEnumerationConcurrent
populator:^(NSUInteger index){
return [NSNumber numberWithInt:(2 * index + 3)];
}];
NSLog(@"My objects: %@",myArray);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment