Contents

characterOffset(of:within:)

Returns the character offset of a position in a document’s text that falls within a specified range.

Declaration

optional func characterOffset(of position: UITextPosition, within range: UITextRange) -> Int

Parameters

  • position:

    An object that identifies a location in a document’s text.

  • range:

    An object that specifies a range of text in a document.

Return Value

The number of characters in a document’s text that occur between position and the beginning of range.

Discussion

You should implement this method if you don’t have a one-to-one correspondence between UITextPosition objects within the given range and character offsets into a document string.

See Also

Reconciling text position and character offset