Skip to content

Instantly share code, notes, and snippets.

@uliwitness
Created April 18, 2012 17:47
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uliwitness/2415382 to your computer and use it in GitHub Desktop.
Save uliwitness/2415382 to your computer and use it in GitHub Desktop.
An (untested) macro and category for easily creating new index sets from unchanging content.
@interface NSIndexSet (ULIIndexSetCreation)
+(NSIndexSet*) indexSetWithIndexes: (const NSInteger [])indexes count: (NSUInteger)count;
@end
@implementation NSIndexSet (ULIIndexSetCreation)
+(NSIndexSet*) indexSetWithIndexes: (const NSInteger [])indexes count: (NSUInteger)count
{
if( count < 1 )
return [NSIndexSet indexSet];
NSMutableIndexSet * muIdxSet = [[[NSMutableIndexSet alloc] initWithIndex: indexes[0]] autorelease];
for( int x = 1; x < count; x++ )
[muIdxSet addIndex: indexes[x]];
return muIdxSet;
}
@end
#define INDEX_SET(destVar, ...) do { NSInteger idxes[] = { __VA_ARGS__ }; (destVar) = [NSIndexSet indexSetWithIndexes: idxes count: sizeof(idxes) /sizeof(NSInteger)]; } while(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment