János
János

Reputation: 35112

How can I make a CKQuery without predicate?

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?

Upvotes: 23

Views: 3860

Answers (2)

Mick MacCallum
Mick MacCallum

Reputation: 130222

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)

Upvotes: 39

zdestiny
zdestiny

Reputation: 542

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.

Upvotes: 20

Related Questions