mlecoz mlecoz -4 years ago 134
iOS Question

CloudKit: fetching records that have a certain element in a list attribute

I was wondering whether it is possible to form an

NSPredicate
that would do the following in CloudKit:

Suppose that I have some record type A. Suppose that A has some attribute b that is of type
[CKReference]
. Let c be some element of type
CKReference
that could be in b.

I wish to query for all records of type A that have c in the list b. Is it possible to do this with
NSPredicate
?

Thanks in advance!

EDIT

I basically want to do this (CloudKit - NSPredicate for finding all records that contain specified CKReference in a reference list), but in Swift 3. I'm having trouble finding good resources online that explain how to use
contains
in an
NSPredicate
.

Answer Source
var predicates = [NSPredicate]()
predicates.append(NSPredicate(format: "("your key" CONTAINS[cd]%@)", filterString))

and initialising CKrefrence in swift 

let reference = CKReference(recordID: example.recordID, action: .deleteSelf)

you can create CKReference object by using-- let reference = CKReference(recordID: example.recordID, action: .deleteSelf) where example.recordId will be record Id from your CloudKit and after creating you need to have your filter using predicate where predicates.append(NSPredicate(format: "("your key" CONTAINS[cd]%@)", filterString)) filter string will contains reference of your created CKReference object –

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download