An object that provides textual context to a custom keyboard.


protocol UITextDocumentProxy


Through conformance to the UIKeyInput protocol, a text document proxy enables a custom keyboard (which is based on the UIInputViewController class) to insert and delete text, to adjust the position of the insertion point, and to determine whether a text input object is empty. The text document proxy uses the keyboard's textDocumentProxy property to do this.

For more about using a text document proxy, see UIInputViewController and Custom Keyboard in App Extension Programming Guide.


Getting the Text Input Mode

var documentInputMode: UITextInputMode?

The text input mode to use for the keyboard.


Obtaining Textual Context Around the Insertion Point

var documentContextAfterInput: String?

Textual context after the insertion point in the current text input object.


var documentContextBeforeInput: String?

Textual context before the insertion point in the current text input object.


Adjusting the Insertion Point Position

func adjustTextPosition(byCharacterOffset: Int)

Moves the insertion point forward or backward in the current text input object.


Getting the Selected Text

var selectedText: String?

The currently selected text in the document.


Distinguishing Changes in the Document

var documentIdentifier: UUID

The unique identifier for this document.



Inherits From

See Also

Custom Keyboard

protocol UIInputViewAudioFeedback

A property that enables a custom input or keyboard accessory view to play standard keyboard input clicks.

class UIInputViewController

The primary view controller for a custom keyboard app extension.

class UILexicon

A read-only array of term pairs, each in a lexicon entry object, for use by a custom keyboard.

class UILexiconEntry

A read-only term pair, available within a lexicon object, for use by a custom keyboard.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software