---
title: "closestPosition(to:within:)"
framework: uikit
role: symbol
role_heading: Instance Method
path: "uikit/uitextinput/closestposition(to:within:)"
---

# closestPosition(to:within:)

Returns the position in a document that is closest to a specified point in a specified range.

## Declaration

```swift
func closestPosition(to point: CGPoint, within range: UITextRange) -> UITextPosition?
```

## Parameters

- `point`: A point in the view that is drawing a document’s text.
- `range`: An object representing a range in a document’s text.

## Return Value

Return Value An object representing the character position in range that is closest to point.

## See Also

### Working with geometry and hit-testing

- [firstRect(for:)](uikit/uitextinput/firstrect(for:).md)
- [closestPosition(to:)](uikit/uitextinput/closestposition(to:).md)
- [selectionRects(for:)](uikit/uitextinput/selectionrects(for:).md)
- [characterRange(at:)](uikit/uitextinput/characterrange(at:).md)
