---
title: "setSelectionIndexPath(_:)"
framework: appkit
role: symbol
role_heading: Instance Method
path: "appkit/nstreecontroller/setselectionindexpath(_:)"
---

# setSelectionIndexPath(_:)

Sets the tree controller’s current selection.

## Declaration

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

## Parameters

- `indexPath`: The proposed new selection.

## Return Value

Return Value Return true if the selection has changed, otherwise false.

## Discussion

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

## See Also

### Getting the current selection

- [selectionIndexPath](appkit/nstreecontroller/selectionindexpath.md)
- [setSelectionIndexPaths(_:)](appkit/nstreecontroller/setselectionindexpaths(_:).md)
- [selectionIndexPaths](appkit/nstreecontroller/selectionindexpaths.md)
- [selectedObjects](appkit/nstreecontroller/selectedobjects.md)
- [selectedNodes](appkit/nstreecontroller/selectednodes.md)
