How to implement custom UITextInputTokenizer?

I have a UITextView and I use its tokenizer to check what words the user clicks.

My goal is to change what the tokenizer thinks like a word. Currently, it seems that words are defined as consecutive alphanumeric characters, I want the word to be defined as consecutive characters that are not a space character ("").

For example: "foo-bar", "foo / bar" and "foo @@ bar" will currently be treated as two separate words ("foo" and "bar"), but I want everyone to treat them as one word (since none of them contain spaces).

The documentation says about a subclass of the UITextInputStringTokenizer class, but I cannot find a single example of who does this, and I cannot understand how I would like to implement the necessary methods:

func isPosition(position: UITextPosition, atBoundary granularity: UITextGranularity, inDirection direction: UITextDirection) -> Bool func isPosition(position: UITextPosition, withinTextUnit granularity: UITextGranularity, inDirection direction: UITextDirection) -> Bool func positionFromPosition(position: UITextPosition, toBoundary granularity: UITextGranularity, inDirection direction: UITextDirection) -> UITextPosition? func rangeEnclosingPosition(position: UITextPosition, withGranularity granularity: UITextGranularity, inDirection direction: UITextDirection) -> UITextRange? 
+7
ios objective-c tokenize swift uitextview
source share

No one has answered this question yet.

See related questions:

1665
How can I make UITextField move up when there is a keyboard - when editing starts?
1276
How to disable ARC for a single file in a project?
1244
How to sort NSMutableArray with custom objects in it?
1180
How to check if a string contains another string in Objective-C?
958
How to change iOS app name?
928
How do I call Objective-C code from Swift?
795
How to check iOS version?
657
How do you start a block after a delay, for example -performSelector: withObject: afterDelay :?
3
Get currently entered word in UITextView
one
Move cursor to specific position in UITextView

All Articles