Post

Replies

Boosts

Views

Activity

CKQuery with NSPredicate fails when using “CONTAINS” operator
According to Apples Class Reference CKQuery, the operator "CONTAINS" is one of the suported operators. However, that doesn't seem to work. I have a recordtype called myRecord, and a record with filedname "name" type String. I try to fetch the record with two different predicates, one with "==" operator, and one with "CONTAINS" operator.func getRecords(){ let name = "John" let Predicate1 = NSPredicate(format: "name == %@",name) let Predicate2 = NSPredicate(format: "name CONTAINS %@",name) let sort = NSSortDescriptor(key: "Date", ascending: false) let query = CKQuery(recordType: "myRecord", predicate: Predicate1) //let query = CKQuery(recordType: "myRecord", predicate: Predicate2) query.sortDescriptors = [sort] let operation = CKQueryOperation(query: query) operation.desiredKeys = ["name", "Date"] operation.recordFetchedBlock = { (record) in print(record["name"]) operation.queryCompletionBlock = { [unowned self] (cursor, error) in dispatch_async(dispatch_get_main_queue()) { if error == nil { print ("sucess") } else { print("couldn't fetch record error:\(error?.localizedDescription)") } } } CKContainer.defaultContainer().publicCloudDatabase.addOperation(operation) }Using Predicate1, outout is: Optional(John) sucessUsing Predicate2, outout is: couldn't fetch record error:Optional("Field \'name\' has a value type of STRING and cannot be queried using filter type LIST_CONTAINS")Also using [c] to ignore casings gives a crash.How do I use the operator "CONTAINS" correctly, and how do I ignore letter casings?
4
0
2.8k
Feb ’16