Skip to content

Instantly share code, notes, and snippets.

@Koze
Created April 17, 2015 01:32
Show Gist options
  • Save Koze/0f9f47a32cec0890e323 to your computer and use it in GitHub Desktop.
Save Koze/0f9f47a32cec0890e323 to your computer and use it in GitHub Desktop.
Predicate with wildcard vs BEGINSWITH and ENDSWITH
- (void)testWildcard3
{
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF LIKE[c] 'a*a'"];
NSLog(@"%@", predicate);
// SELF LIKE[c] "a*a"
NSLog(@"%d", [predicate evaluateWithObject:@"a"]);
// 0
NSLog(@"%d", [predicate evaluateWithObject:@"aa"]);
// 1
NSLog(@"%d", [predicate evaluateWithObject:@"aba"]);
// 1
}
- (void)testWildcard4
{
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF BEGINSWITH[c] 'a' AND SELF ENDSWITH[c] 'a'"];
NSLog(@"%@", predicate);
// SELF BEGINSWITH[c] "a" AND SELF ENDSWITH[c] "a"
NSLog(@"%d", [predicate evaluateWithObject:@"a"]);
// 1
NSLog(@"%d", [predicate evaluateWithObject:@"aa"]);
// 1
NSLog(@"%d", [predicate evaluateWithObject:@"aba"]);
// 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment