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) -> IntParameters
- 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.