<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.0.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSIndexSet/init(indexesIn:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSIndexSet(im)initWithIndexesInRange:"
  },
  "title" : "init(indexesIn:)"
}
-->

# init(indexesIn:)

Initializes an allocated [`NSIndexSet`](/documentation/Foundation/NSIndexSet) object with an index range.

```
init(indexesIn range: NSRange)
```

## Parameters

`range`

An index range. Must be in the range `0 .. NSNotFound - 1`..

## Return Value

Initialized [`NSIndexSet`](/documentation/Foundation/NSIndexSet) object with `indexRange`.

## Discussion

This method raises an [`rangeException`](/documentation/Foundation/NSExceptionName/rangeException) when `indexRange` would add an index that exceeds the maximum allowed value for unsigned integers.

The resulting index set has a [`firstIndex`](/documentation/Foundation/NSIndexSet/firstIndex) equal to the `location` of `indexRange`, and a [`count`](/documentation/Foundation/NSIndexSet/count) equal to the `length` of `indexRange`. Specifying a zero-length range results in an empty index set.

This method is a designated initializer for [`NSIndexSet`](/documentation/Foundation/NSIndexSet).

## See Also

[`+  indexSetWithIndexesInRange:`](/documentation/Foundation/NSIndexSet/indexSetWithIndexesInRange:)

Creates an index set with an index range.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)