I’ve a UITextView
and a NSTextRange
. How can I get a easy String
akin to the vary?
I can solely see uiTextView.textual content(in: UITextRange)
however I’m not positive if NSTextRange
and UITextRange
are even comparable, or map one to the opposite.
Context on why I am attempting to do that:
I’ve some textual content within the UITextView
and I need to work out what portion of the textual content did match the body and which portion didn’t. So I do:
let textLayoutManager = textView.textLayoutManager!
let rangeOfRenderedText: NSTextRange = textLayoutManager.textLayoutFragment(for: CGPointZero)!.rangeInElement
let rangeOfRemainderText: NSTextRange = NSTextRange(location: rangeOfRenderedText.endLocation)
let stringThatFit: String = // use rangeOfRenderedText by some means
let stringThatDidNotFit: String = // use rangeOfRemainderText by some means