---
title: affinity
framework: appkit
role: symbol
role_heading: Instance Property
path: appkit/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](appkit/nstextselection/affinity-swift.enum.md)
- [anchorPositionOffset](appkit/nstextselection/anchorpositionoffset.md)
- [granularity](appkit/nstextselection/granularity-swift.property.md)
- [NSTextSelection.Granularity](appkit/nstextselection/granularity-swift.enum.md)
- [isLogical](appkit/nstextselection/islogical.md)
- [isTransient](appkit/nstextselection/istransient.md)
- [secondarySelectionLocation](appkit/nstextselection/secondaryselectionlocation.md)
- [NSTextLocation](appkit/nstextlocation.md)
- [textRanges](appkit/nstextselection/textranges.md)
- [typingAttributes](appkit/nstextselection/typingattributes.md)
