CloudKit - “Invalid bundle ID for container”

I've just create a project in Xcode 9 beta 6 and add this code:


let privateDB = CKContainer.default().privateCloudDatabase 
let greatID = CKRecordID(recordName: "GreatPlace") 
let place = CKRecord(recordType: "Place", recordID: greatID) 
privateDB.save(place) { (record, error) in
      if error != nil { 
          let er = (error as! CKError).errorUserInfo 
          print("Error: \n") 
          print("CKErrorDescription: \(er["CKErrorDescription"]!)\n") 
          print("ContainerID: \(er["ContainerID"]!)\n")
          print("NSDebugDescription: \(er["NSDebugDescription"]!)\n")
          print("NSUnderlyingError: \(er["NSUnderlyingError"]!)\n")
          print("NSLocalizedDescription: \(er["NSLocalizedDescription"]!)\n")
          print("ServerErrorDescription: \(er["ServerErrorDescription"]!)\n")
    }
    if record != nil { 
          print("record: \(record!)") 
    }
}


and add icloud capabilities with Use default containers and when I run the code I receive this erros message:


Error:
CKErrorDescription: Error saving record <CKRecordID: 0x7fd8e9684560; recordName=GreatPlace, zoneID=_defaultZone:__defaultOwner__> to server: Invalid bundle ID for container
ContainerID: iCloud.com.gazapps.MyCloudKit
NSDebugDescription: CKInternalErrorDomain: 2007
NSUnderlyingError: <CKError 0x60400005d0d0: "Permission Failure" (2007); server message = "Invalid bundle ID for container"; uuid = 73EDDA3F-25B1-4B22-8E8E-4F6B27B9AB06; container ID = "iCloud.com.gazapps.MyCloudKit">
NSLocalizedDescription: Error saving record <CKRecordID: 0x7fd8e9684560; recordName=GreatPlace, zoneID=_defaultZone:__defaultOwner__> to server: Invalid bundle ID for container
ServerErrorDescription: Invalid bundle ID for container


What I am doing wrong ?

Are you sure it's not simply a permissions failure, and the bundle ID fail is just collateral damage?

This happens sometimes when creating a new project, do the following:

  1. Go to developer.apple.com and sign in
  2. Select Certificates, Identifiers & Profiles
  3. Select Identifiers (App IDs)
  4. Edit App ID for the app
  5. Uncheck iCloud
  6. Save
  7. Check iCloud
  8. Quit Xcode and Clear DerivedData
  9. Run app