Class

NSIndexSet

An immutable collection of unique integer values that represent indexes in another collection.

Declaration

@interface NSIndexSet : NSObject

Overview

The NSIndexSet class represents an immutable collection of unique unsigned integers, known as indexes because of the way they are used. This collection is referred to as an index set. Indexes must be in the range 0 .. NSNotFound - 1.

You use index sets in your code to store indexes into some other data structure. For example, given an NSArray object, you could use an index set to identify a subset of objects in that array.

You should not use index sets to store an arbitrary collection of integer values because index sets store indexes as sorted ranges. This makes them more efficient than storing a collection of individual integers. It also means that each index value can only appear once in the index set.

The designated initializers of the NSIndexSet class are: init, initWithIndexesInRange:, and initWithIndexSet:.

You must not subclass the NSIndexSet class.

The mutable subclass of NSIndexSet is NSMutableIndexSet.

Topics

Creating Index Sets

+ indexSet

Creates an empty index set.

+ indexSetWithIndex:

Creates an index set with an index.

+ indexSetWithIndexesInRange:

Creates an index set with an index range.

- init

Initializes an allocated NSIndexSet object.

- initWithIndex:

Initializes an allocated NSIndexSet object with an index.

- initWithIndexesInRange:

Initializes an allocated NSIndexSet object with an index range.

- initWithIndexSet:

Initializes an allocated NSIndexSet object with an index set.

Querying Index Sets

- containsIndex:

Indicates whether the index set contains a specific index.

- containsIndexes:

Indicates whether the receiving index set contains a superset of the indexes in another index set.

- containsIndexesInRange:

Indicates whether the index set contains the indexes represented by an index range.

- intersectsIndexesInRange:

Indicates whether the index set contains any of the indexes in a range.

count

The number of indexes in the index set.

- countOfIndexesInRange:

Returns the number of indexes in the index set that are members of a given range.

- indexPassingTest:

Returns the index of the first object that passes the predicate Block test.

- indexesPassingTest:

Returns an NSIndexSet containing the receiving index set’s objects that pass the Block test.

- indexWithOptions:passingTest:

Returns the index of the first object that passes the predicate Block test using the specified enumeration options.

- indexesWithOptions:passingTest:

Returns an NSIndexSet containing the receiving index set’s objects that pass the Block test using the specified enumeration options.

- indexInRange:options:passingTest:

Returns the index of the first object in the specified range that passes the predicate Block test.

- indexesInRange:options:passingTest:

Returns an NSIndexSet containing the receiving index set’s objects in the specified range that pass the Block test.

Enumerating Index Set Content

- enumerateRangesInRange:options:usingBlock:

Enumerates over the ranges in the range of objects using the block

- enumerateRangesUsingBlock:

Executes a given block using each object in the index set, in the specified ranges.

- enumerateRangesWithOptions:usingBlock:

Executes a given block using each object in the index set, in the specified ranges.

Comparing Index Sets

- isEqualToIndexSet:

Indicates whether the indexes in the receiving index set are the same indexes contained in another index set.

Getting Indexes

firstIndex

The first index in the index set.

lastIndex

The last index in the index set.

- indexLessThanIndex:

Returns either the closest index in the index set that is less than a specific index or the not-found indicator.

- indexLessThanOrEqualToIndex:

Returns either the closest index in the index set that is less than or equal to a specific index or the not-found indicator.

- indexGreaterThanOrEqualToIndex:

Returns either the closest index in the index set that is greater than or equal to a specific index or the not-found indicator.

- indexGreaterThanIndex:

Returns either the closest index in the index set that is greater than a specific index or the not-found indicator.

- getIndexes:maxCount:inIndexRange:

The index set fills an index buffer with the indexes contained both in the index set and in an index range, returning the number of indexes copied.

Enumerating Indexes

- enumerateIndexesUsingBlock:

Executes a given Block using each object in the index set.

- enumerateIndexesWithOptions:usingBlock:

Executes a given Block over the index set’s indexes, using the specified enumeration options.

- enumerateIndexesInRange:options:usingBlock:

Executes a given Block using the indexes in the specified range, using the specified enumeration options.

Relationships

Inherits From

See Also

Indexes

NSIndexPath

A list of indexes that together represent the path to a specific location in a tree of nested arrays.

NSMutableIndexSet

A mutable collection of unique integer values that represent indexes in another collection.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software