How to create range based on a string. With below code, I'm getting the error "Cannot convert the value of type 'Range' to expected argument type 'UITextRange'". FYI print(firstString[range]) successfully output "xxx".
class ViewController: UIViewController {
@IBOutlet weak var textView: UITextView!
let firstString: String = "xxx"
let secondString: String = "yyy"
override func viewDidLoad() {
super.viewDidLoad()
textView.text = firstString
}
func replace() {
var finalString: String?
let range = firstString.startIndex..<firstString.endIndex
print(firstString[range])
textView.replace(range, withText: secondString)
}
@IBAction func replaceButton(_ sender: Any) {
replace()
}
}
textView.text.replace(range, withText: secondString)
– Salman Ghumsani