SwiftUI sheet with TextField using autocorrectionDisabled() prevents view model deinit after editing
I present a view as a sheet that contains a TextField and a viewModel. The sheet uses .autocorrectionDisabled() on the TextField. If I open the sheet and dismiss it without editing, the viewModel is released as expected. But if I edit the TextField and then dismiss the sheet, the viewModel is not deinitialized (it remains retained). Test Outputs: // # Present 1st time - Correct ✅ TestViewModel - init - 0x0000600000c12ee0 // Dismiss wihtout editing, deinitialized correctly TestViewModel - deinit - 0x0000600000c12ee0 // # Present 2st time - Incorrect ❌ TestViewModel - init - 0x0000600000c006c0 // Edit and dismiss, no deinit here // # Present 3rd time - Incorrect ❌ TestViewModel - init - 0x0000600000c113b0 // Enter text field to edit will deinit previous one TestViewModel - deinit - 0x0000600000c006c0 // Dismiss, no deinit // TestViewModel (0x0000600000c113b0) remains retained ⚠️ Using .autocorrectionDisabled(true) gives the same problem. Removing or commenting out .autocorrectionDisabled() fixes the issue, but
Topic:
UI Frameworks
SubTopic:
SwiftUI