---
title: "setSelectedRange(_:)"
framework: appkit
role: symbol
role_heading: Instance Method
path: "appkit/nstextview/setselectedrange(_:)"
---

# setSelectedRange(_:)

Selects the specified range of characters in response to user action.

## Declaration

```swift
func setSelectedRange(_ charRange: NSRange)
```

## Parameters

- `charRange`: The range of characters to select. The range must begin and end on glyph boundaries and not split base glyphs and their nonspacing marks.

## Discussion

Discussion Calling this method resets the selectionGranularity property to NSSelectionGranularity.selectByCharacter and the selectionAffinity property to NSSelectionAffinity.upstream.

## See Also

### Managing the selection

- [selectedRanges](appkit/nstextview/selectedranges.md)
- [setSelectedRange(_:affinity:stillSelecting:)](appkit/nstextview/setselectedrange(_:affinity:stillselecting:).md)
- [setSelectedRanges(_:affinity:stillSelecting:)](appkit/nstextview/setselectedranges(_:affinity:stillselecting:).md)
- [selectionAffinity](appkit/nstextview/selectionaffinity.md)
- [selectionGranularity](appkit/nstextview/selectiongranularity.md)
- [insertionPointColor](appkit/nstextview/insertionpointcolor.md)
- [updateInsertionPointStateAndRestartTimer(_:)](appkit/nstextview/updateinsertionpointstateandrestarttimer(_:).md)
- [selectedTextAttributes](appkit/nstextview/selectedtextattributes.md)
- [markedTextAttributes](appkit/nstextview/markedtextattributes.md)
- [linkTextAttributes](appkit/nstextview/linktextattributes.md)
- [characterIndexForInsertion(at:)](appkit/nstextview/characterindexforinsertion(at:).md)
- [updateCandidates()](appkit/nstextview/updatecandidates().md)
