<!--
{
  "availability" : [
    "macOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSTreeController/setSelectionIndexPath(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSTreeController(im)setSelectionIndexPath:"
  },
  "title" : "setSelectionIndexPath(_:)"
}
-->

# setSelectionIndexPath(_:)

Sets the tree controller’s current selection.

```
func setSelectionIndexPath(_ indexPath: IndexPath?) -> Bool
```

## Parameters

`indexPath`

The proposed new selection.

## Return Value

Return <doc://com.apple.documentation/documentation/Swift/true> if the selection has changed, otherwise <doc://com.apple.documentation/documentation/Swift/false>.

## Discussion

Attempting to change the selection may cause a `commitEditing` message which fails, thus denying the selection change.

---

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)