title: No records in public database using CloudKit and Core Data
body: <p>My goal is to provide a global/public database to all users using CloudKit and Core Data but only I can add or change it. Therefore I think that a public database is the right choice for me. Here is my problem: With the private database there are no problems, all entries exist and are correct. But when I changed the <code>datascope</code> to <code>public</code>, it does not work anymore.</p>
  <p>For testing I used this project <a href="https://github.com/dannysantoso/Medium-Article-CoreData-and-CloudKit" rel="nofollow noreferrer">https://github.com/dannysantoso/Medium-Article-CoreData-and-CloudKit</a> and changed the persistentContainer to</p>
  <pre><code> lazy var persistentContainer: NSPersistentCloudKitContainer = {
          let container = NSPersistentCloudKitContainer(name: &quot;LocalStorageModel&quot;)
          
          
          guard let description = container.persistentStoreDescriptions.first else {
              fatalError(&quot;### \(#function): Failed to retrieve a persistent store description&quot;)
          }
        
          description.setOption(true as NSNumber, forKey: NSPersistentHistoryTrackingKey)
          description.setOption(true as NSNumber, forKey: NSPersistentStoreRemoteChangeNotificationPostOptionKey)
          description.cloudKitContainerOptions?.databaseScope = .public
          
          container.loadPersistentStores(completionHandler: { (storeDescription, error) in
              if let error = error as NSError?{
                  //Error Condition
              }
          })
          
          
          container.viewContext.automaticallyMergesChangesFromParent = true
          container.viewContext.mergePolicy = NSMergeByPropertyObjectTrumpMergePolicy
  
          do {
              try container.initializeCloudKitSchema(options: NSPersistentCloudKitContainerSchemaInitializationOptions())
          } catch {
              print(&quot;Cloud schema error found: \(error)&quot;)
          }
          
          return container
      }()
  </code></pre>
  <p>I also add two indices to Record Types in the iCloud dashboard, namely recordName and modifiedTimestamp. <a href="https://i.stack.imgur.com/dtdSu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dtdSu.png" alt="enter image description here" /></a>
  I do not know why the added data will not sync or be uploaded to the public database. As mentioned with private database there are no problems.</p>