---
title: IndexSet
framework: foundation
role: symbol
role_heading: Structure
path: foundation/indexset
---

# IndexSet

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

## Declaration

```swift
struct IndexSet
```

## Overview

Overview The range of valid integer values is 0...Int.max-1. Anything outside this range is an error.

## Topics

### Creating an Index Set

- [init()](foundation/indexset/init().md)
- [init(integer:)](foundation/indexset/init(integer:).md)
- [init(integersIn:)](foundation/indexset/init(integersin:)-40cz3.md)

### Counting Items in a Set

- [count(in:)](foundation/indexset/count(in:)-v622.md)

### Accessing Elements

- [subscript(_:)](foundation/indexset/subscript(_:).md)

### Combining Index Sets

- [formIntersection(_:)](foundation/indexset/formintersection(_:).md)
- [formSymmetricDifference(_:)](foundation/indexset/formsymmetricdifference(_:).md)
- [formUnion(_:)](foundation/indexset/formunion(_:).md)
- [intersection(_:)](foundation/indexset/intersection(_:).md)
- [symmetricDifference(_:)](foundation/indexset/symmetricdifference(_:).md)
- [union(_:)](foundation/indexset/union(_:).md)

### Inserting Elements

- [insert(_:)](foundation/indexset/insert(_:).md)
- [insert(integersIn:)](foundation/indexset/insert(integersin:)-28eld.md)
- [update(with:)](foundation/indexset/update(with:).md)

### Removing Elements

- [remove(_:)](foundation/indexset/remove(_:).md)
- [remove(integersIn:)](foundation/indexset/remove(integersin:)-7dhfw.md)
- [remove(integersIn:)](foundation/indexset/remove(integersin:)-54370.md)
- [removeAll()](foundation/indexset/removeall().md)

### Testing Set Membership

- [contains(_:)](foundation/indexset/contains(_:).md)
- [contains(integersIn:)](foundation/indexset/contains(integersin:)-9frtv.md)
- [contains(integersIn:)](foundation/indexset/contains(integersin:)-sma8.md)
- [intersects(integersIn:)](foundation/indexset/intersects(integersin:)-3sdmv.md)

### Manipulating Indexes

- [startIndex](foundation/indexset/startindex.md)
- [endIndex](foundation/indexset/endindex.md)
- [index(after:)](foundation/indexset/index(after:).md)
- [index(before:)](foundation/indexset/index(before:).md)
- [formIndex(after:)](foundation/indexset/formindex(after:).md)
- [formIndex(before:)](foundation/indexset/formindex(before:).md)
- [indexRange(in:)](foundation/indexset/indexrange(in:)-539lz.md)

### Finding Elements

- [integerLessThanOrEqualTo(_:)](foundation/indexset/integerlessthanorequalto(_:).md)
- [integerGreaterThan(_:)](foundation/indexset/integergreaterthan(_:).md)
- [integerGreaterThanOrEqualTo(_:)](foundation/indexset/integergreaterthanorequalto(_:).md)
- [integerLessThan(_:)](foundation/indexset/integerlessthan(_:).md)

### Selecting Elements

- [filteredIndexSet(in:includeInteger:)](foundation/indexset/filteredindexset(in:includeinteger:)-6cdvc.md)
- [filteredIndexSet(in:includeInteger:)](foundation/indexset/filteredindexset(in:includeinteger:)-9dn86.md)
- [filteredIndexSet(includeInteger:)](foundation/indexset/filteredindexset(includeinteger:).md)

### Iterating Over Elements

- [makeIterator()](foundation/indexset/makeiterator().md)

### Shifting Index Groups

- [shift(startingAt:by:)](foundation/indexset/shift(startingat:by:).md)

### Getting a Range-Based View

- [rangeView(of:)](foundation/indexset/rangeview(of:)-5xqe8.md)
- [rangeView](foundation/indexset/rangeview-swift.property.md)
- [IndexSet.RangeView](foundation/indexset/rangeview-swift.struct.md)

### Using Reference Types

- [NSIndexSet](foundation/nsindexset.md)
- [NSMutableIndexSet](foundation/nsmutableindexset.md)

### Structures

- [IndexSet.Index](foundation/indexset/index.md)

### Initializers

- [init(integersIn:)](foundation/indexset/init(integersin:)-2zs95.md)
- [init(integersIn:)](foundation/indexset/init(integersin:)-54nqd.md)

### Instance Properties

- [count](foundation/indexset/count.md)
- [first](foundation/indexset/first.md)
- [isEmpty](foundation/indexset/isempty.md)
- [last](foundation/indexset/last.md)

### Instance Methods

- [contains(integersIn:)](foundation/indexset/contains(integersin:)-4k1o8.md)
- [count(in:)](foundation/indexset/count(in:)-7irji.md)
- [indexRange(in:)](foundation/indexset/indexrange(in:)-6057o.md)
- [insert(integersIn:)](foundation/indexset/insert(integersin:)-9wcrp.md)
- [intersects(integersIn:)](foundation/indexset/intersects(integersin:)-9cq7w.md)
- [rangeView(of:)](foundation/indexset/rangeview(of:)-4jdy1.md)

### Type Aliases

- [IndexSet.Element](foundation/indexset/element.md)

## Relationships

### Conforms To

- [BidirectionalCollection](swift/bidirectionalcollection.md)
- [Collection](swift/collection.md)
- [Copyable](swift/copyable.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomReflectable](swift/customreflectable.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Decodable](swift/decodable.md)
- [Encodable](swift/encodable.md)
- [Equatable](swift/equatable.md)
- [Escapable](swift/escapable.md)
- [ExpressibleByArrayLiteral](swift/expressiblebyarrayliteral.md)
- [Hashable](swift/hashable.md)
- [ReferenceConvertible](foundation/referenceconvertible.md)
- [Sendable](swift/sendable.md)
- [SendableMetatype](swift/sendablemetatype.md)
- [Sequence](swift/sequence.md)
- [SetAlgebra](swift/setalgebra.md)

## See Also

### Indexes

- [IndexPath](foundation/indexpath.md)
