3 Replies
      Latest reply on Sep 7, 2019 12:44 PM by PBK
      mikepost Level 1 Level 1 (0 points)

        Ok, I'm having a tough time trying to figure out the missing pieces of how to integrate Core Data with CloudKit, given in this fantastic talk WWDC19 here. The only thing missing from the talk was a demo on the CloudKit Dashboard - which is an important thing to leave out, because it's completely changed!

         

        I've downloaded the CoreDataCloudKitDemo sample code, and have logged into iCloud on the simulator and set up a container in the dashboard with the same bundle id as the sample code app.

         

        When I run it, it sets up the schema on CloudKit Dashboard as expected. This is verified when I created a post in the app on the simulator, a record type of CD_Post is in the CloudKit Dashboard. That's fine, check.

         

        What it doesn't do though is upload the data. I'm just trying to verify if the data is in CloudKit Dashboard, yet when I do a query on CD_Post I get 0 results. I'm trying on the public database, but I've also tried on the private and shared database with the same results.

         

        On that note, I'm also confused about how to actually specify within code whether to use the public database. In the previous CKContainer you could access either the publicCloudDatabase or privateCloudDatabase attributes. But in the new NSPersistentCloudKitContainer, which is completely uninherited and unrelated to the CKContainer, it doesn't seem to have any ability to reference or set whether you're using public or private databases.

         

        I've waited until near the end of the Xcode beta release, because I thought that incomplete functionality might be taken care of before release. But I'm now concerned about the lack of documentation in how to actually use Core Data with the CloudKit Dashboard, I don't see how anyone is supposed to create an app using this framework ahead of the iOS 13 release.

        • Re: Ambiguity around the new CloudKit Dashboard
          PBK Level 7 Level 7 (3,235 points)

          I am unfamilar with   NSPersistentCloudKitContainer

          but I note that the following references the private database:

           

          https://developer.apple.com/documentation/coredata/nspersistentcloudkitcontainer?language=objc

          A container that encapsulates the Core Data stack in your app and mirrors select persistent stores to a CloudKit private database.

            • Re: Ambiguity around the new CloudKit Dashboard
              mikepost Level 1 Level 1 (0 points)

              Hmm, yeah that's a good point. I noticed that but perhaps didn't pay as much importance to it as what is needed. I see it's expanded on slightly here in the documentation "Mirroring a Core Data Store with CloudKit" too:

               

              Core Data with CloudKit uses a specific record zone in the CloudKit private database, which is accessible only to the current user. If you don’t have an iCloud account, create one that you can use during development.

               

              My understanding of CD4CK was that it basically places CloudKit as a similar BaaS offering as to what Firebase does. I don't understand what the point is from Apple to go through all of this effort, just to be deployed to a private database (ie, from what I understand of CK, basically just the logged in user), instead of the public database for the app. It's very disappointing if they still haven't enabled CloudKit & Core Data sync for all users across an app.

                • Re: Ambiguity around the new CloudKit Dashboard
                  PBK Level 7 Level 7 (3,235 points)

                  > I don't understand what the point is from Apple to go through all of this effort, just to be deployed to a private database (ie, from what I understand of CK, basically just the logged in user),

                   

                  The purpose is so that the user can synch their various Apple devices (iPhone, Mac, iPad).

                   

                  >It's very disappointing if they still haven't enabled .... Core Data sync for all users across an app.

                   

                  Perhaps they will. I am unfamiliar with Core Data but maintaining a database for multiple users is a different use-case then for a single user.  Perhaps CloudKit itself, without Core Data, does that better.