---
title: selectionAffinity
framework: uikit
role: symbol
role_heading: Instance Property
path: uikit/uitextinput/selectionaffinity
---

# selectionAffinity

The desired location for the insertion point.

## Declaration

```swift
optional var selectionAffinity: UITextStorageDirection { get set }
```

## Discussion

Discussion For text selections that wrap across line boundaries, this property determines whether the insertion point appears after the last character on the line or before the first character on the following line. The selection affinity is set in response to the user navigating via the keyboard (for example, command-right-arrow). The text input system checks this property when it moves the insertion point around in a document. In the default implementation, if the selection is not at the end of the line, or if the selection is at the start of a paragraph for an empty line, a forward direction is assumed (UITextStorageDirection.forward); otherwise, a backward direction UITextStorageDirection.backward is assumed.

## See Also

### Working with marked and selected text

- [selectedTextRange](uikit/uitextinput/selectedtextrange.md)
- [markedTextRange](uikit/uitextinput/markedtextrange.md)
- [markedTextStyle](uikit/uitextinput/markedtextstyle.md)
- [setMarkedText(_:selectedRange:)](uikit/uitextinput/setmarkedtext(_:selectedrange:).md)
- [setAttributedMarkedText(_:selectedRange:)](uikit/uitextinput/setattributedmarkedtext(_:selectedrange:).md)
- [unmarkText()](uikit/uitextinput/unmarktext().md)
