Wednesday, July 23, 2025

Ways SwiftData’s ModelContainer Can Error on Creation

Scott Driggers:

Here’s what I see from a typical report from a crashing user device. The first thing that jumps out is that there is no explanation from the SwiftData error itself.

[…]

But thankfully, we have the logs to look through. In this example, there are a few level=Error logs from com.apple.coredata that look promising[…]

[…]

Looking through similar reports I have received so far, I can see a few distinct crash reasons

  1. Error due to schema mismatch (this is the example we reviewed above)
  2. Error due to no free space on disk
  3. Error due to multiple migrators attempting to migrate the database concurrently

Core Data has always logged more helpful information than it returns back in the NSError, but at least it usually gives you a reasonable error code. (They aren’t all listed in the documentation; see CoreDataErrors.h and FoundationErrors.h.) Swift has fancy error handling, but somehow the new framework bundles these disparate failures into a generic loadIssueModelContainer error with no associated information.

Previously:

Comments RSS · Twitter · Mastodon

Leave a Comment