Skip to content

Instantly share code, notes, and snippets.

@mikepj
Last active December 10, 2015 16:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikepj/4459727 to your computer and use it in GitHub Desktop.
Save mikepj/4459727 to your computer and use it in GitHub Desktop.
A category to NSIndexSet. Only method will compare the receiver with another NSIndexSet and return a new NSIndexSet with the indices that intersect.
//
// NSIndexSet+GSIndexSetAdditions.h
//
// Created by Mike Piatek-Jimenez on 1/4/13.
// Copyright (c) 2013 Mike Piatek-Jimenez. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface NSIndexSet (GSIndexSetAdditions)
- (NSIndexSet *) gsIntersectionWithIndexSet:(NSIndexSet *)otherSet;
@end
//
// NSIndexSet+GSIndexSetAdditions.m
//
// Created by Mike Piatek-Jimenez on 1/4/13.
// Copyright (c) 2013 Mike Piatek-Jimenez. All rights reserved.
//
#import "NSIndexSet+GSIndexSetAdditions.h"
@implementation NSIndexSet (GSIndexSetAdditions)
- (NSIndexSet *) gsIntersectionWithIndexSet:(NSIndexSet *)otherSet {
NSMutableIndexSet *finalSet = [[[NSMutableIndexSet alloc] init] autorelease];
[self enumerateIndexesUsingBlock:^(NSUInteger index, BOOL *stop) {
if ([otherSet containsIndex:index]) [finalSet addIndex:index];
}];
return finalSet;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment