---
title: "textSelection(for:enclosing:)"
framework: uikit
role: symbol
role_heading: Instance Method
path: "uikit/nstextselectionnavigation/textselection(for:enclosing:)"
---

# textSelection(for:enclosing:)

Returns a text selection expanded to the nearest boundaries for the selection granularity and enclosing text selection text ranges you specify.

## Declaration

```swift
func textSelection(for selectionGranularity: NSTextSelection.Granularity, enclosing textSelection: NSTextSelection) -> NSTextSelection
```

## Parameters

- `selectionGranularity`: One of the available doc://com.apple.uikit/documentation/UIKit/NSTextSelection/Granularity-swift.enum options.
- `textSelection`: The text selection that describes the text range of interest.

## Return Value

Return Value A new text selection.

## See Also

### Working with text selections

- [textSelections(interactingAt:inContainerAt:anchors:modifiers:selecting:bounds:)](uikit/nstextselectionnavigation/textselections(interactingat:incontainerat:anchors:modifiers:selecting:bounds:).md)
- [destinationSelection(for:direction:destination:extending:confined:)](uikit/nstextselectionnavigation/destinationselection(for:direction:destination:extending:confined:).md)
