iOS Creating an NSPredicate Using predicateWithBlock


Example

Objective-C

NSPredicate *predicate = [NSPredicate predicateWithBlock:^BOOL(id item, 
                                                               NSDictionary *bindings) {
    return [item isKindOfClass:[UILabel class]];
}];

Swift

let predicate = NSPredicate { (item, bindings) -> Bool in
    return item.isKindOfClass(UILabel.self)
}

In this example, the predicate will match items that are of the class UILabel.