SwiftData model in Swift package

Hi,

I am looking for information on how to setup a ModelContainer for a Swift app when the SwiftData model is located in a Swift package.

Let's say the model code resides in a package called DomainModel. That package was added target's embedded content and the model types are used to init the model container using the modelContainer(for:) view modifier on the ContentView of the app.

This crashes the app on startup with a EXC_BAD_ACCESS code=2. When copying the model code from the package directly into the app, the app starts just fine.

I kindly ask for a code sample or any information about how to setup the model container when using a model from a Swift package.

Thanks in advance and I am looking forward to replacing CoreData 🙂

This seems to be a currently existing SwiftData bug as several of us are seeing the same thing. I know I am also getting the exact same issue and nothing seems to fix it. Hoping there is an update soon to fix this.

I filed a bug report. Let's hope this one gets fixed fast 🤞

This issue continues to exist with Xcode 15.0 Beta 2 and iOS17 Beta 2.

I am continuing to see this issue as well and have opened a new thread with some code samples and where it's crashing, so feel free to follow that one as well.

I have also seen in a few different places that TTS in particular is failing with the same error and I suspect they may be related, so linking a related TTS thread as well: https://developer.apple.com/forums/thread/732335

I had a working app in Xcode Beta 2, but now in Beta 5 I am seeing a very similar issue. I am creating the ModelContainer from a url which points into an AppGroup container. The app hangs for a long time before crashing with a segfault EXC_BAD_ACCESS (code=2, address=0x16f96bff8). The fact that it's a segfault makes me think that something is happening on the wrong thread, as it should be some more safe error if there is e.g. a migration issue with the SQLite storage.

I ran into the same issue recently, and it ended up being a property name in one of my models causing the crash. For anyone else finding this thread after running into this, here's my thread

SwiftData model in Swift package
 
 
Q