Use public CloudKit database (NSPersistentCloudkitContainer) - macOS

Viewed 479

I’ve written an iOS app in SwiftUI (using the SwiftUI life cycle in Xcode 12) that uses my CloudKit container’s public database with the following lines of code:

 let container = NSPersistentCloudKitContainer(name: "my_ios_container_name")
    
 guard let description = container.persistentStoreDescriptions.first else {
     print("Can't set description")
     fatalError("Error")
 }
    
 description.cloudKitContainerOptions?.databaseScope = .public

I’m in the process of writing a macOS app in SwiftUI that accesses the same CloudKit container’s public database. But when I try to build the code below in my mac app's AppDelegate.swift file, Xcode gives me an error saying that it’s unable to find the ‘databaseScope’ member. Is this member variable only available for iOS apps? If this is the case, how do you access a Cloudkit container's public database in a macOS app?

enter image description here

1 Answers

Try adding "import CloudKit" to the top of the file.

Resolved this issue for me.

Related