I had the same problem running the Apple CloudKit sample application :"CloudPhotos". The app does not run properly because it gets the error while doing the initial fetch for photos from the public database.
the error is:
APLCloudManager ERROR [CKErrorDomain:12] Field 'recordName' is not marked queryable, Error Domain=CKInternalErrorDomain Code=2015 "Field 'recordName' is not marked queryable"
then the app (on iPhone or OSX) misbehave (crash), but it is because of weak error handling due to the error above.
In the dashboard, at first I could not add the index for recordName in the public database, I was getting an OP LOCK error, but after using the dashboard itself to make queries, using filters and confirming that I had some records, a couple hours into it, I was finally able to add the index, and then everything worked!
So, you should be able to make the recordName queryable in the dashboard, and then I suppose your code will work!
ok, but you didn't explain the procedure you used to "add the index". So this isn't helpful. Nowhere in the CloudKit dashboard (circa Fall 2019) is there a navigable area to "make the recordName queryable". ???