{"id":48618,"date":"2025-07-23T13:11:19","date_gmt":"2025-07-23T17:11:19","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=48618"},"modified":"2025-07-23T13:11:19","modified_gmt":"2025-07-23T17:11:19","slug":"ways-swiftdatas-modelcontainer-can-error-on-creation","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2025\/07\/23\/ways-swiftdatas-modelcontainer-can-error-on-creation\/","title":{"rendered":"Ways SwiftData&rsquo;s ModelContainer Can Error on Creation"},"content":{"rendered":"<p><a href=\"https:\/\/scottdriggers.com\/blog\/swiftdata-modelcontainer-creation-crash\/\">Scott Driggers<\/a>:<\/p>\n<blockquote cite=\"https:\/\/scottdriggers.com\/blog\/swiftdata-modelcontainer-creation-crash\/\"><p>Here&rsquo;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 <code>SwiftData<\/code> error itself.<\/p><p>[&#8230;]<\/p><p>But thankfully, we have the logs to look through. In this example, there are a few <code>level=Error<\/code> logs from <code>com.apple.coredata<\/code> that look promising[&#8230;]<\/p><p>[&#8230;]<\/p><p>Looking through similar reports I have received so far, I can see a few distinct crash reasons<\/p><ol><li>Error due to schema mismatch (this is the example we reviewed above)<\/li><li>Error due to no free space on disk<\/li><li>Error due to multiple migrators attempting to migrate the database concurrently<\/li><\/ol><\/blockquote>\n\n<p>Core Data has always logged more helpful information than it returns back in the <code>NSError<\/code>, but at least it usually gives you a reasonable error code. (They aren&rsquo;t all listed in the <a href=\"https:\/\/developer.apple.com\/documentation\/coredata\/nscoredataerror\">documentation<\/a>; see <tt>CoreDataErrors.h<\/tt> and <tt>FoundationErrors.h<\/tt>.) Swift has fancy error handling, but somehow the new framework bundles these disparate failures into a generic <a href=\"https:\/\/developer.apple.com\/documentation\/swiftdata\/swiftdataerror\/loadissuemodelcontainer\">loadIssueModelContainer<\/a> error with no associated information.<\/p>\n\n<p>Previously:<\/p>\n<ul>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2025\/06\/19\/swiftdata-and-core-data-at-wwdc25\/\">SwiftData and Core Data at WWDC25<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2024\/10\/16\/returning-to-core-data\/\">Returning to Core Data<\/a><\/li>\n<\/ul>","protected":false},"excerpt":{"rendered":"<p>Scott Driggers: Here&rsquo;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.[&#8230;]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[&#8230;][&#8230;]Looking through [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"2025-07-23T17:11:22Z","apple_news_api_id":"2930c5dd-951b-4f05-b04e-ea8b358c8aa2","apple_news_api_modified_at":"2025-07-23T17:11:22Z","apple_news_api_revision":"AAAAAAAAAAD\/\/\/\/\/\/\/\/\/\/w==","apple_news_api_share_url":"https:\/\/apple.news\/AKTDF3ZUbTwWwTuqLNYyKog","apple_news_coverimage":0,"apple_news_coverimage_caption":"","apple_news_is_hidden":false,"apple_news_is_paid":false,"apple_news_is_preview":false,"apple_news_is_sponsored":false,"apple_news_maturity_rating":"","apple_news_metadata":"\"\"","apple_news_pullquote":"","apple_news_pullquote_position":"","apple_news_slug":"","apple_news_sections":"\"\"","apple_news_suppress_video_url":false,"apple_news_use_image_component":false,"footnotes":""},"categories":[4],"tags":[109,31,2586,30,2598,857,71,901,2404],"class_list":["post-48618","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-coredata","tag-ios","tag-ios-18","tag-mac","tag-macos-15-sequoia","tag-nserror","tag-programming","tag-swift-programming-language","tag-swiftdata"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/48618","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/comments?post=48618"}],"version-history":[{"count":1,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/48618\/revisions"}],"predecessor-version":[{"id":48619,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/48618\/revisions\/48619"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=48618"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=48618"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=48618"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}