Hey developers! I updated to Xcode 16 and iOS 18. I wanted to publish my first iOS 18 update but I keep getting a very strange error after building and launching the app: "Fatal error: This model instance was destroyed by calling ModelContext.reset and is no longer usable." (I haven't changed anything regarding swift data and I never call ModelContext.reset)
This error happens only after building. When I close the app and open it again (without running it through Xcode) the app never crashes and all the data is still there. I couldn't find much bout this error online. Is anyone experiencing the same?
I wonder if this is a bug in Xcode 16 or there is something wrong with my code. I also wonder if I can safely publish my update to App Store, since the error only happens after building. Thank you!
The error seems to be the same as what was discussed in the iOS 18 SwiftData ModelContext reset post. You might take a look to see if that helps.
The error typically happens when you try to access a model instance after the associated model container is (unintentionally) released. You can review your code to see if that is your case, and if yes, avoid that.
Best,
——
Ziqiao Chen
Worldwide Developer Relations.