Try to debug this issue by catching the error when you use one of the database's operations (e.g.: catch, fetch).
Example:
let publicDatabase = CKContainer.default().publicCloudDatabase
publicDatabase.save(record) { (rec, err) in
if let error = err {
print("Error while saving record: \(error)")
}
or use the debugger instead.
You could possibly have a mismatch between the Apple CloudKit container's identifier and the CKContainer.default()
container identifier. You can correct this by choosing the container identifier
let myPublicDatabase = CKContainer.init(identifier: "iCloud.com.abc.def").publicCloudDatabase