<!--
{
  "availability" : [
    "iOS: 5.0.0 -",
    "iPadOS: 5.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.7.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSIndexSet/enumerateRanges(in:options:using:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSIndexSet(im)enumerateRangesInRange:options:usingBlock:"
  },
  "title" : "enumerateRanges(in:options:using:)"
}
-->

# enumerateRanges(in:options:using:)

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

```
func enumerateRanges(in range: NSRange, options opts: NSEnumerationOptions = [], using block: (NSRange, UnsafeMutablePointer<ObjCBool>) -> Void)
```

## Parameters

`range`

The range of items to enumerate. If the range intersects a range of the receiver’s indexes, then that intersection will be passed to the block.

`opts`

A bitmask that specifies the [`NSEnumerationOptions`](/documentation/Foundation/NSEnumerationOptions) for the enumeration.

`block`

The block to apply to elements in the index set.

    The block takes two arguments:

- range: The range of elements.
- stop: A reference to a Boolean value. The block can set the value to <doc://com.apple.documentation/documentation/Swift/true> to stop further processing of the array. The stop argument is an out-only argument. You should only ever set this Boolean to <doc://com.apple.documentation/documentation/Swift/true> within the Block.

## Discussion

By default, the enumeration starts with the first object and continues serially through the indexed set range to the last object in the range. You can specify `NSEnumerationConcurrent` and/or `NSEnumerationReverse` as enumeration options to modify this behavior.

This method executes synchronously.

> Important:
> If the Block parameter is `nil` this method will raise an exception.

---

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)