NSPersistentCloudKitContainer: How to check if data is synced to CloudKit

To quote “Framework Engineer” from a similar question in the Apple Developer forums: “This is a fallacy”. In a distributed system, you can’t truly know if “sync is complete”, as another device, which could be online or offline at the moment, could have unsynced changes. That said, here are some techniques you can use to … Read more

How to sync records between Core Data and CloudKit efficiently

As of iOS 13, there are new API’s that simplify this synchronization for developers. I would recommend you to watch the WWDC19 session about the new synchronization between CoreData and CloudKit. Please note that these new API’s only work for iOS 13+. Video: https://developer.apple.com/videos/play/wwdc2019/202/ In short, you need to start using NSPersistentCloudKitContainer instead of NSPersistentContainer. … Read more

Check if User is Logged into iCloud? Swift/iOS

If you just want to know if the user is logged in to iCloud, the synchronous method can be used: if FileManager.default.ubiquityIdentityToken != nil { print(“iCloud Available”) } else { print(“iCloud Unavailable”) } If the ubiquityIdentityToken is nil and you’d like to know why iCloud isn’t available, you can use the asynchronous method: CKContainer.default().accountStatus { … Read more

Use production CloudKit during development?

Add the following entry to your entitlements file and perform a clean build. This allows you to run your application in Xcode with the CloudKit in the production mode. Entry to add: com.apple.developer.icloud-container-environment with value: Production. Note: Will not work with simulator

How do I delete a CloudKit container?

Apple’s iOS CloudKit documentation: Enable iCloud and Select CloudKit Important: When you select CloudKit, Xcode creates a default container ID based on the bundle ID. Because you can’t delete iCloud containers, verify that your bundle ID is correct in the General pane in Xcode before selecting CloudKit. To change your bundle ID, read Set the … Read more

Using Core Data, iCloud and CloudKit for syncing and backup and how it works together

It’s like this: Core Data on its own, is completely local and does not automatically work with any of Apple’s cloud services. Core Data with iCloud enabled turns on syncing via iCloud. Any changes you save in Core Data are propagated to the cloud, and any changes made in the cloud are automatically downloaded. The … Read more