Tutorial by Examples

Objective-C NSPredicate *predicate = [NSPredicate predicateWithBlock:^BOOL(id item, NSDictionary *bindings) { return [item isKindOfClass:[UILabel class]]; }]; Swift let predicate = NSPredicate { (item, bindings) -> Bool...
Objective-C NSPredicate *predicate = [NSPredicate predicateWithFormat: @"self[SIZE] = %d", 5)]; Swift let predicate = NSPredicate(format: "self[SIZE] >= %d", 5) In this example, the predicate will match items that are arrays with length of at least 5.
An 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 = [templ...
Objective-C NSArray *heroes = @[@"tracer", @"bastion", @"reaper", @"junkrat", @"roadhog"]; NSPredicate *template = [NSPredicate predicateWithFormat:@"self BEGINSWITH $letter"]; NSDictionary *beginsWithRVariables = @{ @"letter&qu...
NSString *emailRegex = @"[A-Z0-9a-z]([A-Z0-9a-z._-]{0,64})+[A-Z0-9a-z]+@[A-Z0-9a-z]+([A-Za-z0-9.-]{0,64})+([A-Z0-9a-z])+\\.[A-Za-z]{2,4}"; NSString *firstNameRegex = @"[0-9A-Za-z\"'-]{2,32}$"; NSString *firstNameRegex = @"[ 0-9A-Za-z]{2,32}$"; NSString *lastNa...
Conditional predicate will be cleaner and safer by using the NSCompoundPredicate class which provides basic boolean operators for the given predicates. Objective-c AND - Condition NSPredicate *predicate = [NSPredicate predicateWithFormat:@"samplePredicate"]; NSPredicate *anotherPre...

Page 1 of 1