"Field 'recordName' is not marked queryable" error when accessing cloud kit data

I am trying to load a list from cloud kit and getting a "Field 'recordName' is not marked queryable". The record type list is queryable. The field recordName is a system generated field that I cannot modify in the cloudkit dashboard. What can I do to load these items?



let predicate: NSPredicate = NSPredicate(value: true)

let query: CKQuery = CKQuery(recordType: "List", predicate: predicate)

tView.text = "Fetching Icloud data"

db.perform(query, inZoneWith: nil) { (records: [CKRecord]?, error: Error?) in

if error != nil || records == nil{

print("Error in load: \(error!)")

return

} else{

var aList:[String] = []

for i in 0..<records!.count{

let record:CKRecord = records![i]

aList.append(record.object(forKey: "item") as! String)

}

print("Records: \(records!)")

OperationQueue.main.addOperation {

self.tView.text = aList.joined(separator: "\n")

}

}

}

Post not yet marked as solved Up vote post of Ruppert20 Down vote post of Ruppert20
5.4k views

Answers

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". ???

are you able to figured out why it's happening ? any solution?

In the Dashboard:

1) Select your container. Then choose "Schema".

2) In the sidebar select the record you want.

3) With the record selected in the sidebar you should see a list of "System fields" and "Custom fields". Scroll to the bottom and click the "Edit Indexes."

4) You'll now see a pop up button appear in the "Fields" column. Choose "recordName" (if it isn't already selected in the pop up button) then choose "Queryable" in the pop up button in the "Index Type" column. Click "Add Index".

5) Click "Save Changes" to save.

I agree that it's kind of unintuitive!

From 'record types' you click on the 'edit indexes' button below the custom fields.

Then you click 'add index'. This didn't make sense to me as a button label - but it immediately popped up 'record type' and a drop down to make it queryable.

HTH
Do we have to manually set this up in dashboard before the app goes into production? If so, how does that work?

Is there a way to set this up in code?

Thanks!
Good questions. I would like to know too. I cannot find a good explanation online.