---
title: "caretRect(for:)"
framework: uikit
role: symbol
role_heading: Instance Method
path: "uikit/uitextinput/caretrect(for:)"
---

# caretRect(for:)

Returns a rectangle to draw the caret at a specified insertion point.

## Declaration

```swift
func caretRect(for position: UITextPosition) -> CGRect
```

## Parameters

- `position`: An object that identifies a location in a text input area.

## Return Value

Return Value A rectangle that defines the area for drawing the caret.

## Discussion

Discussion The system uses this value to calculate the length of the beam—the vertical line representing the pointer—when using a trackpad to interact with a text input area. You must implement this method even if text never becomes editable, and an insertion point caret never appears.

## See Also

### Related Documentation

- [firstRect(for:)](uikit/uitextinput/firstrect(for:).md)
- [UIPointerShape.verticalBeam(length:)](uikit/uipointershape-swift.enum/verticalbeam(length:).md)

### Providing the caret layout information

- [caretTransform(for:)](uikit/uitextinput/carettransform(for:).md)
