<!--
{
  "availability" : [
    "iOS: -",
    "iPadOS: -",
    "macCatalyst: -",
    "tvOS: -",
    "visionOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/UITextInputTokenizer",
  "metadataVersion" : "0.1.0",
  "role" : "Protocol",
  "symbol" : {
    "kind" : "Protocol",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(pl)UITextInputTokenizer"
  },
  "title" : "UITextInputTokenizer"
}
-->

# UITextInputTokenizer

A tokenizer, which is an object that allows the text input system to evaluate text units of different granularities.

```
@MainActor protocol UITextInputTokenizer : NSObjectProtocol
```

## Overview

Granularities of text units are always evaluated with reference to a storage or reference direction.

Text-processing objects that conform to the [`UITextInput`](/documentation/UIKit/UITextInput) protocol must hold a reference to a tokenizer (through the [`tokenizer`](/documentation/UIKit/UITextInput/tokenizer) property). The [`UITextInputStringTokenizer`](/documentation/UIKit/UITextInputStringTokenizer) class provides a default base implementation of the [`UITextInputTokenizer`](/documentation/UIKit/UITextInputTokenizer) protocol. Tokenizers of this class are suitable for most western-language keyboards. Apps with different requirements may adopt the [`UITextInputTokenizer`](/documentation/UIKit/UITextInputTokenizer) protocol and create their own tokenizers.

## Topics

### Determining text positions relative to unit boundaries

[`isPosition(_:atBoundary:inDirection:)`](/documentation/UIKit/UITextInputTokenizer/isPosition(_:atBoundary:inDirection:))

Return whether a text position is at a boundary of a text unit of a specified granularity in a specified direction.

[`isPosition(_:withinTextUnit:inDirection:)`](/documentation/UIKit/UITextInputTokenizer/isPosition(_:withinTextUnit:inDirection:))

Return whether a text position is within a text unit of a specified granularity in a specified direction.

### Computing text position by unit boundaries

[`position(from:toBoundary:inDirection:)`](/documentation/UIKit/UITextInputTokenizer/position(from:toBoundary:inDirection:))

Return the next text position at a boundary of a text unit of the given granularity in a given direction.

### Getting ranges of specific text units

[`rangeEnclosingPosition(_:with:inDirection:)`](/documentation/UIKit/UITextInputTokenizer/rangeEnclosingPosition(_:with:inDirection:))

Return the range for the text enclosing a text position in a text unit of a given granularity in a given direction.

### Constants

[`UITextDirection`](/documentation/UIKit/UITextDirection)

The direction of the text.

[`UITextGranularity`](/documentation/UIKit/UITextGranularity)

The granularity of a unit of text.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)