Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 887
János Avatar asked Jul 07 '14 21:07

János


2 Answers

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)
like image 138
Mick MacCallum Avatar answered Oct 19 '22 20:10

Mick MacCallum


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.

like image 43
zdestiny Avatar answered Oct 19 '22 20:10

zdestiny