---
title: NSIndexSet
framework: foundation
role: symbol
role_heading: Class
path: foundation/nsindexset
---

# NSIndexSet

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

## Declaration

```swift
class NSIndexSet
```

## Overview

Overview In Swift, this type bridges to IndexSet; use NSIndexSet when you need reference semantics or other Foundation-specific behavior. 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(index:), init(indexesIn:), and init(indexSet:). You must not subclass the NSIndexSet class. The mutable subclass of NSIndexSet is NSMutableIndexSet. important: The Swift overlay to the Foundation framework provides the IndexSet structure, which bridges to the NSIndexSet class and its mutable subclass, NSMutableIndexSet. For more information about value types, see Working with Foundation Types.

## Topics

### Creating Index Sets

- [init(index:)](foundation/nsindexset/init(index:).md)
- [init(indexesIn:)](foundation/nsindexset/init(indexesin:).md)
- [init(indexSet:)](foundation/nsindexset/init(indexset:).md)

### Querying Index Sets

- [contains(_:)](foundation/nsindexset/contains(_:)-bb19.md)
- [contains(_:)](foundation/nsindexset/contains(_:)-5j2kh.md)
- [contains(in:)](foundation/nsindexset/contains(in:).md)
- [intersects(in:)](foundation/nsindexset/intersects(in:).md)
- [count](foundation/nsindexset/count.md)
- [countOfIndexes(in:)](foundation/nsindexset/countofindexes(in:).md)
- [index(passingTest:)](foundation/nsindexset/index(passingtest:).md)
- [indexes(passingTest:)](foundation/nsindexset/indexes(passingtest:).md)
- [index(options:passingTest:)](foundation/nsindexset/index(options:passingtest:).md)
- [indexes(options:passingTest:)](foundation/nsindexset/indexes(options:passingtest:).md)
- [index(in:options:passingTest:)](foundation/nsindexset/index(in:options:passingtest:).md)
- [indexes(in:options:passingTest:)](foundation/nsindexset/indexes(in:options:passingtest:).md)

### Enumerating Index Set Content

- [enumerateRanges(in:options:using:)](foundation/nsindexset/enumerateranges(in:options:using:).md)
- [enumerateRanges(_:)](foundation/nsindexset/enumerateranges(_:).md)
- [enumerateRanges(options:using:)](foundation/nsindexset/enumerateranges(options:using:).md)

### Comparing Index Sets

- [isEqual(to:)](foundation/nsindexset/isequal(to:).md)

### Getting Indexes

- [firstIndex](foundation/nsindexset/firstindex.md)
- [lastIndex](foundation/nsindexset/lastindex.md)
- [indexLessThanIndex(_:)](foundation/nsindexset/indexlessthanindex(_:).md)
- [indexLessThanOrEqual(to:)](foundation/nsindexset/indexlessthanorequal(to:).md)
- [indexGreaterThanOrEqual(to:)](foundation/nsindexset/indexgreaterthanorequal(to:).md)
- [indexGreaterThanIndex(_:)](foundation/nsindexset/indexgreaterthanindex(_:).md)
- [getIndexes(_:maxCount:inIndexRange:)](foundation/nsindexset/getindexes(_:maxcount:inindexrange:).md)

### Enumerating Indexes

- [enumerate(_:)](foundation/nsindexset/enumerate(_:).md)
- [enumerate(options:using:)](foundation/nsindexset/enumerate(options:using:).md)
- [enumerate(in:options:using:)](foundation/nsindexset/enumerate(in:options:using:).md)
- [makeIterator()](foundation/nsindexset/makeiterator().md)
- [NSIndexSetIterator](foundation/nsindexsetiterator.md)

### Initializers

- [init(coder:)](foundation/nsindexset/init(coder:).md)
- [init(indexesInRange:)](foundation/nsindexset/init(indexesinrange:)-67dvw.md)
- [init(indexesInRange:)](foundation/nsindexset/init(indexesinrange:)-n2eh.md)

### Default Implementations

- [Sequence Implementations](foundation/nsindexset/sequence-implementations.md)

## Relationships

### Inherits From

- [NSObject](objectivec/nsobject-swift.class.md)

### Inherited By

- [NSMutableIndexSet](foundation/nsmutableindexset.md)

### Conforms To

- [CVarArg](swift/cvararg.md)
- [Copyable](swift/copyable.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Equatable](swift/equatable.md)
- [Escapable](swift/escapable.md)
- [Hashable](swift/hashable.md)
- [NSCoding](foundation/nscoding.md)
- [NSCopying](foundation/nscopying.md)
- [NSMutableCopying](foundation/nsmutablecopying.md)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)
- [NSSecureCoding](foundation/nssecurecoding.md)
- [Sequence](swift/sequence.md)
