I need to query all the record types, without any filtering. I tried two ways:
let query = CKQuery(recordType: "Pm", predicate: nil)
let query = CKQuery(recordType: "Pm", predicate: NSPredicate(format: ""))
I got error:
'NSInvalidArgumentException', reason: 'Unable to parse the format string ""'
How to do?
You can't perform a query without a predicate, but NSPredicate does have a method just for this, and in Swift it's used through the initializer:
init(value: Bool) -> NSPredicate // return predicates that always evaluate to true/false
Usage is as follows.
let predicate = NSPredicate(value: true)
To get all your records, you will need to use this as the predicate for your CKQuery:
[NSPredicate predicateWithFormat:@"TRUEPREDICATE"]
or, in Swift:
NSPredicate(format: "TRUEPREDICATE")
This effectively works like not having any predicate.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With