首页 技术 正文
技术 2022年11月12日
0 收藏 432 点赞 4,734 浏览 1329 个字

技术博客http://www.cnblogs.com/ChenYilong/ 
新浪微博http://weibo.com/luohanchenyilong 
NSPredicate–谓词(is)
NSPredicate–谓词(is)
NSPredicate–谓词(is)
NSPredicate 
技术博客http://www.cnblogs.com/ChenYilong/新浪微博http://weibo.com/luohanchenyilong
NSPredicate–谓词(is) NSPredicate–谓词(is)
NSPredicate–谓词(is)

• 作用:判断条件表达式的求值返回真或假的过程
• 使用步骤:- 1. 定义NSPredicate对象并指定条件-2. 调用谓词的evaluateWithObject方法判断指定条件是否满足
• 示例:NSPredicate *predicate = [NSPredicatepredicateWithFormat:@”self
CONTAINS ‘1’”];
NSString *text = @”1234″;
NSLog(@”%d”, [predicate evaluateWithObject:text]);
NSPredicate–谓词(is)
谓词示例(1)传统方法 
• 1. 创建Person的对象数组 
• 2. 编写常规的查询判断姓名和年龄的过滤方法NSMutableArray *result = [NSMutableArrayarrayWithCapacity:personList.count]; 
for (NSInteger i = 0; i < personList.count; i++) { Person*person = personList[i]; 
// 用户年龄小于5 同时用户姓名中包含“1”字符串 if(person.age < 5 && NSNotFound != [person.namerangeOfString:@”1″].location) { 
[result addObject:person]; } 
}
return result; 
NSPredicate–谓词(is)
谓词示例(2)谓词方法 NSPredicate*predicate = [NSPredicatepredicateWithFormat:@”name
CONTAINS ‘1’ && %K BETWEEN {%d, %d}”,@”age”, 5, 15];
NSArray *result = [personListfilteredArrayUsingPredicate:predicate];
NSPredicate–谓词(is)
谓词的条件指令(1)逻辑指令 
• &&!
• ||!
• !!
• <!
• <=!
• ==!
• >!
• >=!
• BETWEEN {}!
NSPredicate–谓词(is)
谓词的条件指令(2)字符串匹配 
• BEGANWITH:以指定字符开始• ENDSWITH:以指定字符结束• CONTAINS:包含指定字符,可使用修饰符
– c 不区分大小写
– d 不区分注音符号 • LIKE:使用通配符匹配
– ? 一个字符- * 0个或多个字符
NSPredicate–谓词(is)
提示 
• 1.谓词中的匹配指令关键字通常使用大写字母• 2.谓词中可以使用格式字符串• 3.如果通过对象的keypath指定匹配条件,需要使用%K 
NSPredicate–谓词(is)
Thanks! 
NSPredicate–谓词(is)
NSPredicate–谓词(is)

技术博客http://www.cnblogs.com/ChenYilong/ 
新浪微博http://weibo.com/luohanchenyilong

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,078
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,553
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,402
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,177
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,814
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,898