<!--
{
  "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/NSIndexPath",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSIndexPath"
  },
  "title" : "NSIndexPath"
}
-->

# NSIndexPath

A list of indexes that together represent the path to a specific location in a tree of nested arrays.

```
class NSIndexPath
```

## Overview

In Swift, this object bridges to [`IndexPath`](/documentation/Foundation/IndexPath); use [`NSIndexPath`](/documentation/Foundation/NSIndexPath) when you need reference semantics or other Foundation-specific behavior.

Each index in an index path represents the index into an array of children from one node in the tree to another, deeper, node. For example, the index path `1.4.3.2` specifies the path shown in [Figure 1](/documentation/foundation/nsindexpath#1965825).

![Index path “1.4.3.2”](images/com.apple.foundation/media-1965825.gif)

> Note:
> The UIKit framework adds programming interfaces to the `NSIndexPath` class of the Foundation framework to facilitate the identification of rows and sections in <doc://com.apple.documentation/documentation/UIKit/UITableView> objects and the identification of items and sections in <doc://com.apple.documentation/documentation/UIKit/UICollectionView> objects. The API consists of class factory methods and properties for accessing the various indexed values. You use the factory methods to create an index path for the corresponding table view or collection view.

> Important:
> The Swift overlay to the Foundation framework provides the ``doc://com.apple.foundation/documentation/Foundation/IndexPath`` structure, which bridges to the ``doc://com.apple.foundation/documentation/Foundation/NSIndexPath`` class. For more information about value types, see <doc://com.apple.documentation/documentation/Swift/working-with-foundation-types>.

## Topics

### Creating and Initializing Index Paths

[`+  indexPathWithIndex:`](/documentation/Foundation/NSIndexPath/indexPathWithIndex:)

Creates a one-node index path.

[`+  indexPathWithIndexes:length:`](/documentation/Foundation/NSIndexPath/indexPathWithIndexes:length:)

Creates an index path with one or more nodes.

[`-  initWithIndex:`](/documentation/Foundation/NSIndexPath/init(index:))

Initializes an index path with a single node.

[`-  initWithIndexes:length:`](/documentation/Foundation/NSIndexPath/init(indexes:length:))

Initializes an index path with the given nodes and length.

### Using Special Node Names

<doc://com.apple.documentation/documentation/UIKit> and <doc://com.apple.documentation/documentation/AppKit> supply specialized names for the first two index path nodes for use when working with table views and collection views.

[`+  indexPathForRow:inSection:`](/documentation/Foundation/NSIndexPath/init(forRow:inSection:))

Initializes an index path with the indexes of a specific row and section in a table view.

[`+  indexPathForItem:inSection:`](/documentation/Foundation/NSIndexPath/init(forItem:inSection:))

Initializes an index path with the indexes of a specific item and section in a collection view.

[`section`](/documentation/Foundation/NSIndexPath/section)

An index number identifying a section in a table view or collection view.

[`row`](/documentation/Foundation/NSIndexPath/row)

An index number identifying a row in a section of a table view.

[`item`](/documentation/Foundation/NSIndexPath/item)

An index number identifying an item in a section of a collection view.

### Counting Nodes

[`length`](/documentation/Foundation/NSIndexPath/length)

The number of nodes in the index path.

### Adding and Removing Nodes

[`-  indexPathByAddingIndex:`](/documentation/Foundation/NSIndexPath/adding(_:))

Returns an index path containing the nodes in the receiving index path plus another given index.

[`-  indexPathByRemovingLastIndex`](/documentation/Foundation/NSIndexPath/removingLastIndex())

Returns an index path with the nodes in the receiving index path, excluding the last one.

### Comparing Index Paths

[`-  compare:`](/documentation/Foundation/NSIndexPath/compare(_:))

Indicates the depth-first traversal order of the receiving index path and another index path.

### Working with Indexes

[`-  indexAtPosition:`](/documentation/Foundation/NSIndexPath/index(atPosition:))

Provides the value at a particular node in the index path.

[`-  getIndexes:range:`](/documentation/Foundation/NSIndexPath/getIndexes(_:range:))

Copies the indexes stored in the index path from the positions specified by the position range into the specified indexes.

[`-  getIndexes:`](/documentation/Foundation/NSIndexPath/getIndexes(_:))

Copies the objects contained in the index path into indexes.

## Relationships

### Conforms To

[`Escapable`](/documentation/Swift/Escapable)

[`CustomStringConvertible`](/documentation/Swift/CustomStringConvertible)

[`NSCopying`](/documentation/Foundation/NSCopying)

[`CustomDebugStringConvertible`](/documentation/Swift/CustomDebugStringConvertible)

[`Hashable`](/documentation/Swift/Hashable)

[`CVarArg`](/documentation/Swift/CVarArg)

[`Equatable`](/documentation/Swift/Equatable)

[`NSCoding`](/documentation/Foundation/NSCoding)

[`Copyable`](/documentation/Swift/Copyable)

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

[`NSSecureCoding`](/documentation/Foundation/NSSecureCoding)

### Inherits From

[`NSObject-swift.class`](/documentation/ObjectiveC/NSObject-swift.class)

---

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)