CloudKit Server Rejected Request: Unknown field recordName

470 Views Asked by At

I am doing a CKQuery like this in Swift 4:

CKQuery(recordType: package.recordType, predicate: 
  NSPredicate(format: "NOT (recordName IN %@)", package.recordNames as CVarArg))

...and I'm getting this CKError:

CKError(_nsError: CKError 0x60000024dce0: "Server Rejected Request" (15/2000); server message = "Unknown field 'recordName'"; uuid = BCD7C8DA-04B0-4422-8A24-F6479D234706; container ID = "...")

Is there a special key to use when querying against the recordName?

1

There are 1 best solutions below

0
On

After digging some more, I discovered that you cannot query by the recordName directly, but you can query by the recordID. So instead of comparing an array of strings, you have to build an array of CKRecordIDs and query like this:

//- 1 - Build an array of CKRecordIDs
package.recordIDs = [CKRecordID(recordName: "..."), CKRecordID(recordName: "...")]

//- 2 - Set the predicate to use the `recordID` key
let pred = NSPredicate(format: "NOT (recordID IN %@)", package.recordIDs as CVarArg)

//- 3 - Set the query and drop your mic
CKQuery(recordType: package.recordType, predicate: pred)

I hope that helps someone else.