DEV Community

Caleb Hearth
Caleb Hearth

Posted on • Originally published at calebhearth.com on

Using WidgetKit + SwiftData

Yesterday I was setting up my first widget, scratching an itch I’ve had for a while “empty states” in some lock screen widgets and watch complications. I was following a couple of articles by Majid Jabrayilov, which I found really useful in getting some of the boilerplate set up for adding a widget extension to an app. Something those posts don’t touch on is integrating with the main app’s persistent data store, in my case SwiftData.

Working on it myself, I quickly ran into a process crash in Previews and the Simulator. The crash report included this snippet:

CrashReportError: Fatal Error in ModelContainer.swift

MyWidgetExtension crashed due to fatalError in ModelContainer.swift at line 144.

failed to find a currently active container for MyModel

Read More

Top comments (0)