---
title: NSTextSelection
framework: uikit
role: symbol
role_heading: Class
path: uikit/nstextselection
---

# NSTextSelection

A class that represents a single logical selection context that corresponds to an insertion point.

## Declaration

```swift
class NSTextSelection
```

## Topics

### Creating a text selection

- [init(_:affinity:)](uikit/nstextselection/init(_:affinity:).md)
- [init(range:affinity:granularity:)](uikit/nstextselection/init(range:affinity:granularity:).md)
- [init(_:affinity:granularity:)](uikit/nstextselection/init(_:affinity:granularity:).md)
- [init(coder:)](uikit/nstextselection/init(coder:).md)

### Characteristics of a selection

- [affinity](uikit/nstextselection/affinity-swift.property.md)
- [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)

### Creating subselections

- [textSelection(_:)](uikit/nstextselection/textselection(_:).md)

### Initializers

- [init(location:affinity:)](uikit/nstextselection/init(location:affinity:).md)
- [init(ranges:affinity:granularity:)](uikit/nstextselection/init(ranges:affinity:granularity:).md)

## Relationships

### Inherits From

- [NSObject](objectivec/nsobject-swift.class.md)

### Conforms To

- [CVarArg](swift/cvararg.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Equatable](swift/equatable.md)
- [Hashable](swift/hashable.md)
- [NSCoding](foundation/nscoding.md)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)
- [NSSecureCoding](foundation/nssecurecoding.md)

## See Also

### Location and selection

- [NSTextRange](uikit/nstextrange.md)
- [NSTextSelectionNavigation](uikit/nstextselectionnavigation.md)
- [NSTextLocation](uikit/nstextlocation.md)
