Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.