{"id":3289,"date":"2023-06-10T15:38:30","date_gmt":"2023-06-10T19:38:30","guid":{"rendered":"https:\/\/michaelrowe01.com\/?p=3289"},"modified":"2023-06-10T15:38:33","modified_gmt":"2023-06-10T19:38:33","slug":"migrate-to-swiftdata","status":"publish","type":"post","link":"https:\/\/michaelrowe01.com\/index.php\/blog\/migrate-to-swiftdata\/","title":{"rendered":"Migrate to Swiftdata"},"content":{"rendered":"\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"660\" height=\"371\" data-attachment-id=\"3290\" data-permalink=\"https:\/\/michaelrowe01.com\/index.php\/blog\/migrate-to-swiftdata\/attachment\/%ef%a3%bfwwdc23-37\/\" data-orig-file=\"https:\/\/i0.wp.com\/michaelrowe01.com\/wp-content\/uploads\/2023\/06\/%EF%A3%BFWWDC23-37.png?fit=1920%2C1080&amp;ssl=1\" data-orig-size=\"1920,1080\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"\uf8ffWWDC23-37\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/michaelrowe01.com\/wp-content\/uploads\/2023\/06\/%EF%A3%BFWWDC23-37.png?fit=660%2C371&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/michaelrowe01.com\/wp-content\/uploads\/2023\/06\/%EF%A3%BFWWDC23-37.png?resize=660%2C371&#038;ssl=1\" alt=\"\" class=\"wp-image-3290\" srcset=\"https:\/\/i0.wp.com\/michaelrowe01.com\/wp-content\/uploads\/2023\/06\/%EF%A3%BFWWDC23-37.png?resize=1024%2C576&amp;ssl=1 1024w, https:\/\/i0.wp.com\/michaelrowe01.com\/wp-content\/uploads\/2023\/06\/%EF%A3%BFWWDC23-37.png?resize=300%2C169&amp;ssl=1 300w, https:\/\/i0.wp.com\/michaelrowe01.com\/wp-content\/uploads\/2023\/06\/%EF%A3%BFWWDC23-37.png?resize=768%2C432&amp;ssl=1 768w, https:\/\/i0.wp.com\/michaelrowe01.com\/wp-content\/uploads\/2023\/06\/%EF%A3%BFWWDC23-37.png?resize=1536%2C864&amp;ssl=1 1536w, https:\/\/i0.wp.com\/michaelrowe01.com\/wp-content\/uploads\/2023\/06\/%EF%A3%BFWWDC23-37.png?w=1920&amp;ssl=1 1920w, https:\/\/i0.wp.com\/michaelrowe01.com\/wp-content\/uploads\/2023\/06\/%EF%A3%BFWWDC23-37.png?w=1320&amp;ssl=1 1320w\" sizes=\"auto, (max-width: 660px) 100vw, 660px\" \/><\/figure>\n\n\n\n<p>Generate model classes&nbsp;<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Use your managed Object Model to generate your SwiftData model, Open your model file in Xcode and select Editor -> Create SwiftData Code\n<ul class=\"wp-block-list\">\n<li>You can also create the model from class.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<p>Complete adoption<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>When fully monitoring you are replacing the core data stack with swiftData stack<\/li>\n\n\n\n<li>Focus on understanding&nbsp; your core data model designs, and check if they are supported in SwiftData<\/li>\n\n\n\n<li>Highlights\n<ul class=\"wp-block-list\">\n<li>Generate model classes, and delete the CoreData Managed Object model<\/li>\n\n\n\n<li>Delete the persistent file that setup the stack<\/li>\n\n\n\n<li>Setup ModelContainer &#8211; via modifier in a WindowGroup. This also setups the context for the environment<\/li>\n\n\n\n<li>You insert new objects into the modelContext &#8211; it has an implicit save to persist data, you can remove implicit save<\/li>\n\n\n\n<li>You can use Queries instead of FetchRequest<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<p>Coexists with Core Data<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>If you want coexistence you will end up with two different persistent stacks talking to the exiting Store<\/li>\n\n\n\n<li>Before loading the persistent store you will need to make sure you set both stores with the same url and turn on .setOption(true as NSNumber, forKey: NSPersistentHistoryTrackingKey) &#8211; if you don\u2019t do this, you will be in read only mode<\/li>\n\n\n\n<li>SwiftData is only available in IOS17 and macOS Sonoma<\/li>\n\n\n\n<li>Requirements\n<ul class=\"wp-block-list\">\n<li>Use Namespace to ensure there is no collision &#8211; but Entities will stay the same<\/li>\n\n\n\n<li>Keep Schema\u2019s in sync &#8211; adding properties in the same way<\/li>\n\n\n\n<li>You must keep track of Schema Versioning &#8211; Check out Model your Schema with SwiftData from WWDC23&nbsp;<\/li>\n\n\n\n<li>If you are using UIKit or AppKit you need to Core Data<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Generate model classes&nbsp; Complete adoption Coexists with Core Data<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"hide_page_title":"","_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[2,3],"tags":[739,744,691,680],"class_list":["post-3289","post","type-post","status-publish","format-standard","hentry","category-blog","category-personal-softwareandit","tag-day-6","tag-migration","tag-swiftdata","tag-wwdc23"],"aioseo_notices":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p2aMa8-R3","jetpack-related-posts":[],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/michaelrowe01.com\/index.php\/wp-json\/wp\/v2\/posts\/3289","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/michaelrowe01.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/michaelrowe01.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/michaelrowe01.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/michaelrowe01.com\/index.php\/wp-json\/wp\/v2\/comments?post=3289"}],"version-history":[{"count":1,"href":"https:\/\/michaelrowe01.com\/index.php\/wp-json\/wp\/v2\/posts\/3289\/revisions"}],"predecessor-version":[{"id":3291,"href":"https:\/\/michaelrowe01.com\/index.php\/wp-json\/wp\/v2\/posts\/3289\/revisions\/3291"}],"wp:attachment":[{"href":"https:\/\/michaelrowe01.com\/index.php\/wp-json\/wp\/v2\/media?parent=3289"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/michaelrowe01.com\/index.php\/wp-json\/wp\/v2\/categories?post=3289"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/michaelrowe01.com\/index.php\/wp-json\/wp\/v2\/tags?post=3289"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}