Skip to content

Instantly share code, notes, and snippets.

@Koze
Created April 17, 2015 01:15
Show Gist options
  • Save Koze/4bb5d165f050da0e3fd7 to your computer and use it in GitHub Desktop.
Save Koze/4bb5d165f050da0e3fd7 to your computer and use it in GitHub Desktop.
NSPredicate with wildcard
- (void)testWildcard1
{
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF LIKE[c] 'a*e'"];
NSLog(@"%@", predicate);
// SELF LIKE[c] "a*e"
NSLog(@"%d", [predicate evaluateWithObject:@"apple"]);
// 1
NSLog(@"%d", [predicate evaluateWithObject:@"apple watch"]);
// 0
}
- (void)testWildcard2
{
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF LIKE[c] 'a??le'"];
NSLog(@"%@", predicate);
// SELF LIKE[c] "a??le"
NSLog(@"%d", [predicate evaluateWithObject:@"apple"]);
// 1
NSLog(@"%d", [predicate evaluateWithObject:@"appple"]);
// 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment