metatext/Extensions/UITextInput+Extensions.swift

14 lines
339 B
Swift
Raw Normal View History

2021-02-14 02:28:30 +00:00
// Copyright © 2021 Metabolist. All rights reserved.
import UIKit
extension UITextInput {
var textToSelectedRange: String? {
guard let selectedRange = selectedTextRange,
let range = textRange(from: beginningOfDocument, to: selectedRange.end)
else { return nil }
return text(in: range)
}
}