Update: the problem occurs when the app goes to the background, comes back, and SwiftUI tries to access relationships of SwiftData models that are direct input parameters to the View. My app has a function that opens a URL in a browser, it is when you press the Back button and return from the browser to the app that this fatal error tends to occur. When the app goes to the background, the BackingData of every relationship of this main model seems to get replaced with some subclass of FutureBackingData. Accessing them results in the fatal error above. Explicitly querying the relationship with @Query instead of relying on the relationship property seems to solve the problem. It would be great to have some documentation on how exactly SwiftData is behaving when the app goes to the background.
Topic:
Programming Languages
SubTopic:
Swift
Tags: