---
title: "compare(_:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/nsindexpath/compare(_:)"
---

# compare(_:)

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

## Declaration

```swift
func compare(_ otherObject: IndexPath) -> ComparisonResult
```

## Parameters

- `otherObject`: Index path to compare. This value must not be nil. If the value is nil, the behavior is undefined.

## Return Value

Return Value The depth-first traversal ordering of the receiving index path and indexPath.

## Discussion

Discussion ComparisonResult.orderedAscending: The receiving index path comes before indexPath. ComparisonResult.orderedDescending: The receiving index path comes after indexPath. ComparisonResult.orderedSame: The receiving index path and indexPath are the same index path.
