<!--
{
  "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/getIndexes(_:maxCount:inIndexRange:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSIndexSet(im)getIndexes:maxCount:inIndexRange:"
  },
  "title" : "getIndexes(_:maxCount:inIndexRange:)"
}
-->

# getIndexes(_:maxCount:inIndexRange:)

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.

```
func getIndexes(_ indexBuffer: UnsafeMutablePointer<Int>, maxCount bufferSize: Int, inIndexRange range: NSRangePointer?) -> Int
```

## Parameters

`indexBuffer`

Index buffer to fill.

`bufferSize`

Maximum size of `indexBuffer`.

`range`

Index range to compare with indexes in the index set; `nil` represents all the indexes in the index set. Indexes in the index range and in the index set are copied to `indexBuffer`. On output, the range of indexes not copied to `indexBuffer`.

## Return Value

Number of indexes placed in `indexBuffer`.

## Discussion

You are responsible for allocating the memory required for `indexBuffer` and for releasing it later.

Suppose you have an index set with contiguous indexes from 1 to 100. If you use this method to request a range of `(1, 100)`—which represents the set of indexes 1 through 100—and specify a buffer size of `20`, this method returns 20 indexes—1 through 20—in `indexBuffer` and sets `indexRange` to `(21, 80)`—which represents the indexes 21 through 100.

Use this method to retrieve entries quickly and efficiently from an index set. You can call this method repeatedly to retrieve blocks of index values and then process them. When doing so, use the return value and `indexRange` to determine when you have finished processing the desired indexes. When the return value is less than `bufferSize`, you have reached the end of the 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)