博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
iOS OC 谓词筛选
阅读量:6976 次
发布时间:2019-06-27

本文共 1366 字,大约阅读时间需要 4 分钟。

//年龄小于30          //定义谓词对象,谓词对象中包含了过滤条件          NSPredicate *predicate = [NSPredicate predicateWithFormat:@"age<%d",30];          //使用谓词条件过滤数组中的元素,过滤之后返回查询的结果          NSArray *array = [persons filteredArrayUsingPredicate:predicate];          NSLog(@"filterArray=%@",array);                    //查询name=1的并且age大于40  与&&        predicate = [NSPredicate predicateWithFormat:@"name='1' && age>40"];          array = [persons filteredArrayUsingPredicate:predicate];          NSLog(@"filterArray=%@",array);      注:对于变量应使用    predicate = [NSPredicate predicateWithFormat:@"name CONTAINS %@&& age>40",str];                    //in(包含)   或||        predicate = [NSPredicate predicateWithFormat:@"self.name IN {'1','2','4'} || self.age IN{30,40}"];                    //name以a开头的          predicate = [NSPredicate predicateWithFormat:@"name BEGINSWITH 'a'"];          //name以ba结尾的          predicate = [NSPredicate predicateWithFormat:@"name ENDSWITH 'ba'"];                    //name中包含字符a的          predicate = [NSPredicate predicateWithFormat:@"name CONTAINS 'a'"];                    //like 匹配任意多个字符          //name中只要有s字符就满足条件          predicate = [NSPredicate predicateWithFormat:@"name like '*s*'"];          //?代表一个字符,下面的查询条件是:name中第二个字符是s的          predicate = [NSPredicate predicateWithFormat:@"name like '?s'"];

 

转载于:https://www.cnblogs.com/sunmair/p/7216713.html

你可能感兴趣的文章
LeetCode --- Pow(x, n)
查看>>
Ajax.BeginForm 使用过程中遇到的问题
查看>>
Ubuntu Linux系统下apt-get命令详解
查看>>
【spark 深入学习 03】Spark RDD的蛮荒世界
查看>>
Android之Service
查看>>
elasticsearch(1) 安装和使用
查看>>
Windows 平台下局域网劫持测试工具 – EvilFoca
查看>>
HDU 1071 The area ——微积分
查看>>
Windows API 编程----EnumWindows()函数的用法
查看>>
SGU 521 North-East ( 二维LIS 线段树优化 )
查看>>
mac下安装mysql
查看>>
Java
查看>>
Mac 抓包工具 Charles
查看>>
hdoj1014 互质
查看>>
sizeof(Vector<>)大小问题
查看>>
[转]理解 Delphi 的类(十一) - 深入类中的方法[10] - 构造方法与析构方法
查看>>
文件的读取和写出
查看>>
POJ NOI MATH-7826 分苹果
查看>>
二、安装桌面——Linux学习笔记
查看>>
Linq之Linq to XML
查看>>