SwiftUI TextField optional Binding crash
Originator: | indiekiduk | ||
Number: | rdar://FB16555225 | Date Originated: | 2025-02-22 |
Status: | Open | Resolved: | No |
Product: | SwiftUI | Product Version: | 18.2 |
Classification: | Bug | Reproducible: | Always |
This code with optional Binding and TextField crashes: struct ContentView: View { @State var optionalText: String? var body: some View { Button(optionalText == nil ? "Show" : "Hide") { optionalText = optionalText == nil ? "Text" : nil } if let $text = Binding($optionalText) { TextField("", text: $text) } } } This workaround thanks to @iampatbrown prevents the crash: TextField("", text: $text) .transition(.identity) // workaround thanks to @iampatbrown So it seems the crash is related to animation. It seems FB8367784 - a crash with optional Binding and Toggle was reported before and fixed. Hopefully it can be fixed for TextField too, and all the other controls that take bindings. Xcode Version 16.2 (16C5032a) iOS simulator 18.2
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at feedbackassistant.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!