CloudKit - NSPredicate to find all records containing multiple CKReferences in a link list

I am working on a Joke app that uses CloudKit

Each joke has a list of links for some categories / tags.

I am trying to query for all jokes that have specific tags. For example, I want to find all the jokes that are in the animal and doctor categories.

I have now tried with the following code

let tagRecords = tags.map {  CKReference(record: $0.record, action: .None) }
let predicate = NSPredicate(format: "tags CONTAINS %@", tagRecords)
let query = CKQuery(recordType: "Jokes", predicate: predicate)

      

Basically what is stated above is to first create an array of links and then create a predicate to find tags containing those links

Unfortunately it doesn't work I am getting the following error:

server message = "Internal server error" "

So the question is, how do you find all the entries containing all the links in the link list?

+3


source to share


1 answer


Assuming which tags

is a relation or an array of strings, you can try with the following predicate:

let predicate = NSPredicate(format: "ANY tags IN %@", tagRecords)

      



Hope it helps.

+3


source







All Articles