Skip to content

Instantly share code, notes, and snippets.

@robnadin
Created December 21, 2017 14:04
Show Gist options
  • Save robnadin/5991267abf8b8e68d006459c249f55c3 to your computer and use it in GitHub Desktop.
Save robnadin/5991267abf8b8e68d006459c249f55c3 to your computer and use it in GitHub Desktop.
extension UITextField {
func textRange(from range: NSRange) -> UITextRange? {
guard
let startPosition = position(from: beginningOfDocument, offset: range.location),
let endPosition = position(from: startPosition, offset: range.length) else {
return nil
}
return textField.textRange(from: startPosition, to: endPosition)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment