I'm using CloudKit and wish to perform a search for records based on their string fields.
Apple docs say this is the way to do a tokenized search of a record's fields:
To perform a tokenized search of a record’s fields, use the special operator self. A tokenized search searches any fields that have full-text search enabled, which is all string-based fields by default. Listing 5 shows an example that searches the fields of the record for the token strings bob and smith. Each distinct word is treated as a separate token for the purpose of searching. Comparisons are case- and diacritic-insensitive. These token strings may be found in a single field or in multiple fields but all of the tokens must be present in a record for it to be considered a match.
Listing 5: Matching 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 the an exception.
Code:
predicate = [NSPredicate predicateWithFormat:@"self contains 'bob smith'"];
query = [[CKQuery alloc] initWithRecordType:kCKRecord_Level predicate:predicate];
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 that predicate string and CloudKit?
It looks like the 'self contains' does not work anymore. You still do a tokenized search using this predicate:
NSPredicate(format: "allTokens TOKENMATCHES[cdl] %@", "bob smith")
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments