---
title: "characterRange(byExtending:in:)"
framework: uikit
role: symbol
role_heading: Instance Method
path: "uikit/uitextinput/characterrange(byextending:in:)"
---

# characterRange(byExtending:in:)

Returns a text range from a specified text position to its farthest extent in a certain direction of layout.

## Declaration

```swift
func characterRange(byExtending position: UITextPosition, in direction: UITextLayoutDirection) -> UITextRange?
```

## Parameters

- `position`: A text-position object that identifies a location in a document.
- `direction`: A constant that indicates a direction of layout (right, left, up, down).

## Return Value

Return Value A text-range object that represents the distance from position to the farthest extent in direction.

## See Also

### Determining layout and writing direction

- [position(within:farthestIn:)](uikit/uitextinput/position(within:farthestin:).md)
- [baseWritingDirection(for:in:)](uikit/uitextinput/basewritingdirection(for:in:).md)
- [setBaseWritingDirection(_:for:)](uikit/uitextinput/setbasewritingdirection(_:for:).md)
