{"id":35614,"date":"2022-04-18T16:27:06","date_gmt":"2022-04-18T20:27:06","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=35614"},"modified":"2022-04-18T16:27:06","modified_gmt":"2022-04-18T20:27:06","slug":"nspersistentcloudkitcontainer-in-2022","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2022\/04\/18\/nspersistentcloudkitcontainer-in-2022\/","title":{"rendered":"NSPersistentCloudKitContainer in 2022"},"content":{"rendered":"<p><a href=\"https:\/\/twitter.com\/stroughtonsmith\/status\/1514378073231212546\">Steve Troughton-Smith<\/a>:<\/p>\n<blockquote cite=\"https:\/\/twitter.com\/stroughtonsmith\/status\/1514378073231212546\">\n<p>For the longest time, Core Data had a very bad rap for iCloud syncing, so I just never engaged with it even after the APIs were improved. What is the story in 2022? Is Core Data + CloudKit in a good place, or nightmare fuel? What are the current pitfalls? &#8230;should I use it?<\/p>\n<\/blockquote>\n\n<p><a href=\"https:\/\/twitter.com\/bhansmeyer\/status\/1514449519571873792\">Becky Hansmeyer<\/a>:<\/p>\n<blockquote cite=\"https:\/\/twitter.com\/bhansmeyer\/status\/1514449519571873792\">\n<p>It&rsquo;s been nightmare fuel for me, but maybe I just don&rsquo;t have it set up right. I hear from users now and then who say that all of their data has been wiped out, and I have no idea what could have happened.<\/p>\n<\/blockquote>\n\n<p><a href=\"https:\/\/twitter.com\/Roland9\/status\/1514541851675607043\">Roland Gropmair<\/a>:<\/p>\n<blockquote cite=\"https:\/\/twitter.com\/Roland9\/status\/1514541851675607043\">\n<p>I tested it a bit, it <em>seemed<\/em> to work fine. But I never got it working with watchOS - no way to troubleshoot - and left it there<\/p>\n<\/blockquote>\n\n<p><a href=\"https:\/\/twitter.com\/jabwd\/status\/1514896780692918273\">Antwan van Houdt<\/a>:<\/p>\n<blockquote cite=\"https:\/\/twitter.com\/jabwd\/status\/1514896780692918273\">\n<p>For my specific use case it has been a nightmare to optimise the size of the data. My app generates many but small records and this doesn&rsquo;t go well with CoreData + CloudKit. I created a binary format which reduces the amount of records that helps with this problem somewhat.<\/p>\n<\/blockquote>\n\n<p><a href=\"https:\/\/twitter.com\/nutsmuggler\/status\/1514477587015376897\">Davide Benini<\/a>:<\/p>\n<blockquote cite=\"https:\/\/twitter.com\/nutsmuggler\/status\/1514477587015376897\">\n<p>It&rsquo;s quite reliable, a bit hard to set up and debug, but still much simpler than building your own sync system. You&rsquo;ll need to follow Apple&rsquo;s docs to set up sync and reconcile conflicts yourself, but it&rsquo;s a logical process an quite mechanical.<\/p>\n<\/blockquote>\n\n<p><a href=\"https:\/\/twitter.com\/imrabti\/status\/1514522883564920838\">Mrabti<\/a>:<\/p>\n<blockquote cite=\"https:\/\/twitter.com\/imrabti\/status\/1514522883564920838\">\n<p>It works quite good, but I think it is better to have your own sync code instead of using the Apple Blackbox sync implementation, then you will have more control on edge cases, and you can troubleshoot issues much more easier.<\/p>\n<\/blockquote>\n\n<p><a href=\"https:\/\/twitter.com\/BFormations\/status\/1514468198355193858\">Binary Formations<\/a>:<\/p>\n<blockquote cite=\"https:\/\/twitter.com\/BFormations\/status\/1514468198355193858\">\n<p>The built-in CloudKit mirroring stuff is too opaque for our needs.<\/p>\n<\/blockquote>\n\n<p><a href=\"https:\/\/crunchybagel.com\/nspersistentcloudkitcontainer\/\">Quentin Zervaas<\/a>:<\/p>\n<blockquote cite=\"https:\/\/crunchybagel.com\/nspersistentcloudkitcontainer\/\"><p>It is a really elegant solution that mostly works well, but in rolling out this update, we&rsquo;ve come to learn a few things about it.<\/p><p>[&#8230;]<\/p><p>[Just] because an event finishes, doesn&rsquo;t mean everything is in sync yet. You may experience many consecutive events of the same type all within a short timeframe.<\/p><p>[&#8230;]<\/p><p>If an error occurs, it will frequently give you a <code>CKError<\/code>, but these aren&rsquo;t necessarily the same as when accessing CloudKit directly. For example, if you receive a <code>CKError.Code.partialFailure<\/code>, it&rsquo;s not possible retrieve the errors that would normally be contained.<\/p><p>[&#8230;]<\/p><p>For errors that aren&rsquo;t a <code>CKError<\/code>, I haven&rsquo;t been able to find documentation for many of the errors that occur, but these are the ones I&rsquo;ve discovered (I&rsquo;m sure there are more).<\/p><p>[&#8230;]<\/p><p>There&rsquo;s some quirky behaviour with Apple Watch, which can make it challenging to keep everything up-to-date between the Apple Watch and its linked iPhone.<\/p><p>[&#8230;]<\/p><p>Since <code>NSPersistentCloudKitContainer<\/code> uses transactions to keep the data in sync, it needs to propagate through every database changed one by one.<\/p><\/blockquote>\n\n<p>Previously:<\/p>\n<ul>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2022\/01\/24\/increased-icloud-errors\/\">Increased iCloud Errors<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2021\/10\/01\/icloudcoredatastarter-and-temporary-ids-bug\/\">iCloudCoreDataStarter and Temporary IDs Bug<\/a><\/li>\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<li><a href=\"https:\/\/mjtsai.com\/blog\/2016\/06\/17\/the-deprecation-of-icloud-core-data\/\">The Deprecation of iCloud Core Data<\/a><\/li>\n<\/ul>","protected":false},"excerpt":{"rendered":"<p>Steve Troughton-Smith: For the longest time, Core Data had a very bad rap for iCloud syncing, so I just never engaged with it even after the APIs were improved. What is the story in 2022? Is Core Data + CloudKit in a good place, or nightmare fuel? What are the current pitfalls? &#8230;should I use [&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":"2022-04-18T20:27:09Z","apple_news_api_id":"82c3036b-0c5a-4cfb-ba56-2f01c1bb72fc","apple_news_api_modified_at":"2022-04-18T20:27:09Z","apple_news_api_revision":"AAAAAAAAAAD\/\/\/\/\/\/\/\/\/\/w==","apple_news_api_share_url":"https:\/\/apple.news\/AgsMDawxaTPu6Vi8Bwbty_A","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":[916,109,31,1837,2078,30,2077,71,269,1212],"class_list":["post-35614","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-cloudkit","tag-coredata","tag-ios","tag-ios-14","tag-ios-15","tag-mac","tag-macos-12","tag-programming","tag-syncing","tag-watchos"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/35614","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=35614"}],"version-history":[{"count":1,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/35614\/revisions"}],"predecessor-version":[{"id":35615,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/35614\/revisions\/35615"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=35614"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=35614"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=35614"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}