diff --git a/_posts/2024-12-03-text-field-enhancements-in-swiftui.md b/_posts/2024-12-03-text-field-enhancements-in-swiftui.md index d5052d5..f69208e 100644 --- a/_posts/2024-12-03-text-field-enhancements-in-swiftui.md +++ b/_posts/2024-12-03-text-field-enhancements-in-swiftui.md @@ -34,6 +34,13 @@ struct ContentView: View { var body: some View { TextField("Very long text here", text: $text, selection: $selection) + .onChange(of: selection) { + if let selection = selection.take() { + if case let .selection(range) = selection.indices { + print(text[range]) + } + } + } } } ```