Class

NSIndexSet

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.

Overview

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, init(indexesIn:), and init(indexSet:).

You must not subclass the NSIndexSet class.

The mutable subclass of NSIndexSet is NSMutableIndexSet.

Symbols

Creating Index Sets

init(index: Int)

Initializes an allocated NSIndexSet object with an index.

init(indexesIn: NSRange)

Initializes an allocated NSIndexSet object with an index range.

init(indexSet: IndexSet)

Initializes an allocated NSIndexSet object with an index set.

Querying Index Sets

func contains(Int)

Indicates whether the index set contains a specific index.

func contains(IndexSet)

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

func contains(in: NSRange)

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

func intersects(in: NSRange)

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

var count: Int

The number of indexes in the index set.

func countOfIndexes(in: NSRange)

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

func index(passingTest: (Int, UnsafeMutablePointer<ObjCBool>) -> Bool)

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

func indexes(passingTest: (Int, UnsafeMutablePointer<ObjCBool>) -> Bool)

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

func index(options: NSEnumerationOptions = [], passingTest: (Int, UnsafeMutablePointer<ObjCBool>) -> Bool)

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

func indexes(options: NSEnumerationOptions = [], passingTest: (Int, UnsafeMutablePointer<ObjCBool>) -> Bool)

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

func index(in: NSRange, options: NSEnumerationOptions = [], passingTest: (Int, UnsafeMutablePointer<ObjCBool>) -> Bool)

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

func indexes(in: NSRange, options: NSEnumerationOptions = [], passingTest: (Int, UnsafeMutablePointer<ObjCBool>) -> Bool)

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

Enumerating Index Set Content

func enumerateRanges((NSRange, UnsafeMutablePointer<ObjCBool>) -> Void)

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

func enumerateRanges(options: NSEnumerationOptions = [], using: (NSRange, UnsafeMutablePointer<ObjCBool>) -> Void)

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

Comparing Index Sets

func isEqual(to: IndexSet)

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

Getting Indexes

var firstIndex: Int

The first index in the index set.

var lastIndex: Int

The last index in the index set.

func indexLessThanIndex(Int)

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

func indexLessThanOrEqual(to: Int)

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

func indexGreaterThanOrEqual(to: Int)

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

func indexGreaterThanIndex(Int)

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

func getIndexes(UnsafeMutablePointer<Int>, maxCount: Int, inIndexRange: NSRangePointer?)

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

func enumerate((Int, UnsafeMutablePointer<ObjCBool>) -> Void)

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

func enumerate(options: NSEnumerationOptions = [], using: (Int, UnsafeMutablePointer<ObjCBool>) -> Void)

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

func enumerate(in: NSRange, options: NSEnumerationOptions = [], using: (Int, UnsafeMutablePointer<ObjCBool>) -> Void)

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

Instance Methods

func makeIterator()

Return an iterator over the elements of this sequence.