NSPredicate使用(2)——比较运算

前端之家收集整理的这篇文章主要介绍了NSPredicate使用(2)——比较运算前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
NSNumber *testNumber = @123;
// =,==:判断两个表达式是否相等,
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF = 123"];
NSLog(@"%@ vs 123: %@",testNumber,([predicate evaluateWithObject:testNumber] ? @"相等" : @"不相等"));
// >=,=>:判断左边表达式的值是否大于或等于右边表达式的值
predicate = [NSPredicate predicateWithFormat:@"SELF >= 200"];
NSLog(@"%@ vs 200: %@",([predicate evaluateWithObject:testNumber] ? @"大于等于" : @"小于"));
// <=,=<:判断右边表达式的值是否小于或等于右边表达式的值
predicate = [NSPredicate predicateWithFormat:@"SELF <= 150"];
NSLog(@"%@ vs 150: %@",([predicate evaluateWithObject:testNumber] ? @"小于等于" : @"大于"));
// >:判断左边表达式的值是否大于右边表达式的值
predicate = [NSPredicate predicateWithFormat:@"SELF > 123"];
NSLog(@"%@ vs 123: %@",([predicate evaluateWithObject:testNumber] ? @"大于" : @"小于等于"));
// <:判断左边表达式的值是否小于右边表达式的值
predicate = [NSPredicate predicateWithFormat:@"SELF < 123"];
NSLog(@"%@ vs 123: %@",([predicate evaluateWithObject:testNumber] ? @"小于" : @"大于等于"));
// !=、<>:判断两个表达式是否不相等
predicate = [NSPredicate predicateWithFormat:@"SELF != 123"];
NSLog(@"%@ vs 123: %@",([predicate evaluateWithObject:testNumber] ? @"不相等" : @"相等"));
// BETWEEN:BETWEEN表达式必须满足表达式 BETWEEN {下限,上限}的格式,要求该表达式必须大于或等于下限,并小于或等于上限
predicate = [NSPredicate predicateWithFormat:@"SELF BETWEEN {100,200}"];
NSLog(@"%@ vs {100,200}: %@",([predicate evaluateWithObject:testNumber] ? @"包含" : @"不包含"));

运行结果

2018-03-05 15:28:23.701 DemoNSPredicate[2472:315182] 123 vs 123: 相等
2018-03-05 15:28:23.701 DemoNSPredicate[2472:315182] 123 vs 200: 小于
2018-03-05 15:28:23.701 DemoNSPredicate[2472:315182] 123 vs 150: 小于等于
2018-03-05 15:28:23.701 DemoNSPredicate[2472:315182] 123 vs 123: 小于等于
2018-03-05 15:28:23.702 DemoNSPredicate[2472:315182] 123 vs 123: 大于等于
2018-03-05 15:28:23.702 DemoNSPredicate[2472:315182] 123 vs 123: 相等
2018-03-05 15:28:23.702 DemoNSPredicate[2472:315182] 123 vs {100,200}: 包含
2018-03-05 15:28:23.702 DemoNSPredicate[2472:315182] 123 vs 251: 不相等
原文链接:https://www.f2er.com/regex/357629.html

猜你在找的正则表达式相关文章