I have an extension which identify and return the word before the cursor:
extension UITextView {
var currentWord : String? {
let beginning = beginningOfDocument
if let start = position(from: beginning, offset: selectedRange.location),
let end = position(from: start, offset: selectedRange.length) {
let textRange = tokenizer.rangeEnclosingPosition(end, with: .word, inDirection: 1)
if let textRange = textRange {
return text(in: textRange)
}
}
return nil
}
I am using UItextGranularity.word and works fine.
However my issue is this:
If at the beginning of the word i have an @ it won't be returned. so if i have @jon the currentword will be jon. Is there a way to include the @ so to have the complete word with the special Character?
Thank you