{"id":33796,"date":"2021-10-01T17:00:35","date_gmt":"2021-10-01T21:00:35","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=33796"},"modified":"2021-10-01T17:02:27","modified_gmt":"2021-10-01T21:02:27","slug":"icloudcoredatastarter-and-temporary-ids-bug","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2021\/10\/01\/icloudcoredatastarter-and-temporary-ids-bug\/","title":{"rendered":"iCloudCoreDataStarter and Temporary IDs Bug"},"content":{"rendered":"<p><a href=\"https:\/\/github.com\/jazzychad\/iCloudCoreDataStarter\">Chad Etzel<\/a> (<a href=\"https:\/\/twitter.com\/jazzychad\/status\/1443322452914802693\">tweet<\/a>):<\/p>\n<blockquote cite=\"https:\/\/github.com\/jazzychad\/iCloudCoreDataStarter\"><p>In the course of building <a href=\"https:\/\/stickerdoodle.app\">Sticker Doodle<\/a>\n(which you should go download right now), I ran into many brick walls\nand learned way too much about Core Data, iCloud sync, Collection and\nTable Views, and Diffable Data Sources.<\/p><p>There is documentation for each of those individually, but I could\nfind no clear and simple example project that ties them all together\nin a neat little bow.<\/p><p>Well, that changes today.<\/p><p>[&#8230;]<\/p><p>Before <code>.save()<\/code> is called on the managed object context, this\ntemporary ID can be used to fetch the object, refer to it, etc&#8230; it\nacts like a normal <code>NSManagedObjectID<\/code> -- <em>HOWEVER,<\/em> after <code>.save()<\/code>\nis called on the managed object context, 2 things are supposed to\nhappen:<\/p><ol><li><p><code>NSManagedObjects<\/code> with temporary IDs are supposed to be assigned a\npermanent ID and those objects updated in memory with the new ID.<\/p><\/li><li><p>The managed object context <em>forgets all temporary IDs<\/em> and\nattempting to use them to identify an object will <em>fail.<\/em><\/p><\/li><\/ol><p>There seems to be a bug (in iOS 14 and iOS 15 as of my latest testing)\nwhere <em>sometimes<\/em> Step 1 will <em>not actually happen<\/em> and newly inserted\nand saved objects will still have a temporary ID!! This has led to all\nsorts of unexpected and frustrating behavior until I figured out what\nwas actually going on. There are several developer forum posts and\nStack Overflow questions regarding the same behavior, so I am not the\nonly one that has experienced this bug.<\/p><\/blockquote>\n\n<p>Previously:<\/p>\n<ul>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2021\/03\/31\/how-to-set-up-core-data-and-cloudkit\/\">How to Set Up Core Data and CloudKit<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2019\/06\/04\/syncing-core-data-with-cloudkit-and-nspersistentcloudkitcontainer\/\">Syncing Core Data With CloudKit and NSPersistentCloudKitContainer<\/a><\/li>\n<\/ul>","protected":false},"excerpt":{"rendered":"<p>Chad Etzel (tweet): In the course of building Sticker Doodle (which you should go download right now), I ran into many brick walls and learned way too much about Core Data, iCloud sync, Collection and Table Views, and Diffable Data Sources.There is documentation for each of those individually, but I could find no clear and [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"2021-10-01T21:00:39Z","apple_news_api_id":"2290edde-580c-42a5-aa11-615a3741b358","apple_news_api_modified_at":"2021-10-01T21:02:30Z","apple_news_api_revision":"AAAAAAAAAAAAAAAAAAAAAA==","apple_news_api_share_url":"https:\/\/apple.news\/AIpDt3lgMQqWqEWFaN0GzWA","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":[131,916,69,109,16,1837,2078,30,1891,71,269],"class_list":["post-33796","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-bug","tag-cloudkit","tag-cocoa","tag-coredata","tag-icloud","tag-ios-14","tag-ios-15","tag-mac","tag-macos-11-0","tag-programming","tag-syncing"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/33796","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=33796"}],"version-history":[{"count":2,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/33796\/revisions"}],"predecessor-version":[{"id":33802,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/33796\/revisions\/33802"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=33796"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=33796"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=33796"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}