TLDR: When focusing a TextField or TextEditor in a form, each keystroke takes 100% CPU for up to a second (before returning to zero) and total memory goes up by nearly a megabyte (and does not come down).
Details:
- XCode Version 15.1 (15C65)
- iOS 17.0
- Swift 5
I am using SwiftUI and SwiftData. The text editors bind to fields on a SwiftData model. Beyond that, nothing too crazy is happening, I have some onChange handlers but this behavior remains when they’re commented out.
The code is public, and the view containing the problematic fields is here. I suspect it has something to do with SwiftData but I have no idea why – this behavior seems to have come out of nowhere but frankly my work isn’t sufficiently organized to bisect its origin.
I’m not sure I can extract this into a minimal example given the spaghetti nature of my code – I just want to make my app usable again if anyone with SwiftData/CoreData experience has any quick tips for me.
- I removed any onChange and onAppear handlers from the fields – behavior remained
- I removed the modelContext from the offending view, instead passing necessary helpers in a closure – the behavior remained
I’ve done a few other things but really I will retry anything if someone else tells me to; I am not experienced enough with SwiftUI to debug effectively.