CloudKit Unexpected expression for NSPredicate

I am using CloudKit and want to search for records based on their string fields.

Apple docs say this is the way to do tokenized lookups for record fields:

To perform tokenized lookups on record fields, use the special operator self. Bulleted search searches any field that has full text search enabled, by default, these are all string fields. Listing 5 shows an example that looks for record fields for bob and smith string tokens. Each individual word is treated as a separate search token. Comparisons are case and diacritical insensitive. These token strings can be found in a single field or in multiple fields, but all tokens must be present in the record for this to be considered a match.

Listing 5: Mapping a field containing a tokenized string

NSPredicate predicate = nil;
predicate = [NSPredicate predicateWithFormat:@"self contains 'bob smith'"];

      

When I enter this exact string for the predicate, I get an exception.

code:

predicate = [NSPredicate predicateWithFormat:@"self contains 'bob smith'"];
query = [[CKQuery alloc] initWithRecordType:kCKRecord_Level predicate:predicate];

      

An exception:

*** Terminating app due to uncaught exception 'CKException', reason: 'Unexpected expression: SELF CONTAINS "bob smith"'

      


Any ideas what could be wrong? Has anyone had any success with this predicate line and CloudKit?

https://developer.apple.com/library/prerelease/ios/documentation/CloudKit/Reference/CKQuery_class/index.html

+3


source to share


1 answer


It looks like "self contains" doesn't work anymore. You are still doing tokenized lookups using this predicate:



NSPredicate(format: "allTokens TOKENMATCHES[cdl] %@", "bob smith")

      

+3


source







All Articles