Reputation: 449
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
.
Upvotes: 1
Views: 813
Reputation: 449
Here's what ended up working for me, in terms of the variables I used in the question:
let
c= CKReference(recordID: userRecordID!, action: .none)
let joinedPredicate = NSPredicate(format: "%K CONTAINS %@",
b,
c)
.
let joinedQuery = CKQuery(recordType:
A, predicate: joinedPredicate)
Upvotes: 1
Reputation: 1
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 –
Upvotes: 0