When using the code below, the selected text is received multiple seconds after selection. Is there a way to speed this up or a better way to achieve this result?
TextEditor(text: $text)
.introspect(.textEditor, on: .iOS(.v14, .v15, .v16, .v17, .v18)) { textEditor in
if let textRange = textEditor.selectedTextRange {
DispatchQueue.main.async {
let selectedText = textEditor.text(in: textRange) ?? ""
self.selectedText = selectedText
print(self.selectedText)
}
}
}
Checklist
[X] I have read the README before submitting this report.
I was able to fix the issue by assigning the value directly to a variable (inside a view model in my case), rather than initializing a new one and then assigning it like in the example.
Description
When using the code below, the selected text is received multiple seconds after selection. Is there a way to speed this up or a better way to achieve this result?
Checklist
Expected behavior
For the console to log the selected text as soon as it was selected.
Actual behavior
The print statement was executed multiple seconds (more than 5) after selection.
Steps to reproduce
Build and run a view with the following code:
Version information
1.2.0
Destination operating system
iOS 17
Xcode version information
16 beta 4
Swift Compiler version information