Creating an NSPredicate with Substitution Variables
suggest changeAn NSPredicate
can use substitution variables to allow values to be bound on the fly.
Objective-C
NSPredicate *template = [NSPredicate predicateWithFormat: @"self BEGINSWITH $letter"];
NSDictionary *variables = @{ @"letter": @"r" };
NSPredicate *beginsWithR = [template predicateWithSubstitutionVariables: variables];
Swift
let template = NSPredicate(format: "self BEGINSWITH $letter")
let variables = ["letter": "r"]
let beginsWithR = template.predicateWithSubstitutionVariables(variables)
The template predicate is not modified by predicateWithSubstitutionVariables
. Instead, a copy is created, and that copy receives the substitution variables.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents