The issue
While writing an iOS app in Swift using CloudKit and CoreData with NSPersistentCloudKitContainer, I ran into the issue “Field ‘recordName’ is not marked queryable” and couldn’t see an obvious solution. Searching online didn’t give many helpful results either.

This error message would show up in the CloudKit Dashboard as well as in the debug console when trying to make a CloudKit query from my app. My CloudKit scheme, automatically generated by NSPersistentCloudKitContainer, didn’t have a field named “recordName” for me to mark queryable.

Solution
It turns out the solution is quite simple, though not immediately obvious. It’s simply to mark “recordID” as queryable, even though the error message says “recordName”.
To do so, open the CloudKit dashboard, open the development environment for your app, the under Schema -> Indexes, select the record type you’re trying to query. Click the plus button to add a new index, and mark “recordID” as Queryable and click Save.

That field should now be queryable in both the CloudKit Dashboard and in your code using CKQueryOperation.

One thought on “How to fix “Field ‘recordName’ is not marked queryable” in CloudKit”