---
title: affinity
framework: uikit
role: symbol
role_heading: Instance Property
path: uikit/nstextselection/affinity-swift.property
---

# affinity

Returns the selection affinity of the text selection.

## Declaration

```swift
var affinity: NSTextSelection.Affinity { get }
```

## Discussion

Discussion The affinity is NSTextSelection.Affinity.downstream by default. For a zero-length selection, it describes the visual location of the text cursor between the head of line containing the selection location (downstream) or tail of the previous line (upstream). For a selection with contents, it describes the logical direction of non-anchored edge of the selection.

## See Also

### Characteristics of a selection

- [NSTextSelection.Affinity](uikit/nstextselection/affinity-swift.enum.md)
- [anchorPositionOffset](uikit/nstextselection/anchorpositionoffset.md)
- [granularity](uikit/nstextselection/granularity-swift.property.md)
- [NSTextSelection.Granularity](uikit/nstextselection/granularity-swift.enum.md)
- [isLogical](uikit/nstextselection/islogical.md)
- [isTransient](uikit/nstextselection/istransient.md)
- [secondarySelectionLocation](uikit/nstextselection/secondaryselectionlocation.md)
- [NSTextLocation](uikit/nstextlocation.md)
- [textRanges](uikit/nstextselection/textranges.md)
- [typingAttributes](uikit/nstextselection/typingattributes.md)
