Unable to load data from Core Data in SwiftUI app (very rare)

Hey,

We're loading data from Core Data, and for some reason an error is thrown. This is happening extremely rarely and we haven't been able to reproduce it.

The error thrown has the following description:

Åtgärden kunde inte slutföras. (ScreenGenieCore.EnrolledView.(unknown context at $10087af4c).EnrolledError fel 0.)

It is occurring in an app written in SwiftUI when the user taps a button. The managed object context is initiated in app init and provided to the view using the @environment modifier. So the viewContext should always exist. Still it throws an error saying unknown context ....

Any guidance or possible things to investigate would be much appreciated.

Accepted Answer

I got some help and now know what (unknown context at $10087af4c) means. It has nothing to do with Core Data.

It occurs because the error enum I'm throwing is defined inside my class and is private.

Now that I know this, I just need to see where the first case in my custom enum is thrown. This will get me close to the root issue.

Unable to load data from Core Data in SwiftUI app (very rare)
 
 
Q