Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extension UITextView {
- var currentWord: String? {
- let regex = try! NSRegularExpression(pattern: "\\S+$")
- let textRange = NSRange(location: 0, length: selectedRange.location)
- if let range = regex.firstMatch(in: text, range: textRange)?.range {
- return String(text[Range(range, in: text)!])
- }
- return nil
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment