I came across TOKENMATCHES in minute 31 of Introducing CloudKit and was curious, so I did a google search and found very little about it outside of another StackOverflow post.
NSPredicate(format: "ALL tokenize(%@, 'Cdl') IN allTokens", "after session")
Actually, confusing things further, that post uses different syntax than the WWDC video:
NSPredicate(format: "allTokens TOKENMATCHES[cdl] %@", "bob smith")
As I understand it, these queries return any records that have all of the tokenized string arguments within one or more text fields. The latter case would fetch a record with, say, person.name = "bob"
and person.last = "smith"
, as well as, say, a record where person.note = "Bob likes Joseph Smith."
. (Corrections welcome.)
All that said, this question isn't about the full predicate, but just that cdl
(or Cdl
?) parameter/modifier/whateverthehellitis.
TL;DR—What's cdl
mean, and are there other values that can go in that "slot" of the format string?
<rant> Why isn't the predicate syntax documentation comprehensive? It's as if Apple's managers are scared of the mysterious, ancient power that is NSPredicate; none dare assign the technical writer and engineer needed to make this otherwise simple class accessible to the Rest of Us™. A Google search for "nspredicate TOKENMATCHES" gives only 8 results, none of which are at apple.com. 😠 </rant>
Found it, at least!
The doc: NSComparisonPredicateOptions
typedef enum NSComparisonPredicateOptions : NSUInteger {
NSCaseInsensitivePredicateOption = 0x01, //==> [c]
NSDiacriticInsensitivePredicateOption = 0x02, //==> [d]
NSNormalizedPredicateOption = 0x04 //==> [n]
} NSComparisonPredicateOptions;
+ NSLocaleSensitivePredicateOption //==> [l]
So basically :[c]
: uppercase is the same as lowercase (ie: A == a)[d]
: char with diacritics (acute accent, cedilla, etc.) is the same as char without it (ie à == a (accent)[l]
: it's for localized specificities. The Apple sample is with "straße" and "strasse" using the German "double s" (Eszett) as an example.
来源:https://stackoverflow.com/questions/36961555/whats-the-cdl-do-in-tokenmatchescdl