NSPredicate,谓词
原文地址:http://blog.csdn.net/holydancer/article/details/7380799
- #import <Foundation/Foundation.h>
- @interface Human :NSObject
- {
- NSString *name;
- int age;
- Human *child;
- }
- @property (copy)NSString *name;
- @property int age;
- @end
- @implementation Human
- @synthesize name;
- @synthesize age;
- @end
- int main(int argc, const char * argv[])
- {
- @autoreleasepool {
- //利用kvc进行对象初始化
- Human *human = [[Human alloc]init];
- Human *child = [[Human alloc]init];
- [human setValue:@"holydancer" forKey:@"name"];
- [human setValue:[NSNumber numberWithInt:20] forKey:@"age"];
- [human setValue:child forKey:@"child"];
- [human setValue:[NSNumber numberWithInt:5] forKeyPath:@"child.age"];
- NSPredicate *predicate1=[NSPredicate predicateWithFormat:@"name=='holydancer'"];//创建谓词判断属性
- NSPredicate *predicate2=[NSPredicate predicateWithFormat:@"child.age==5"];//创建谓词判断属性的属性
- //此处在创建谓词时可以有好多种条件写法,比如大小比较,范围验证,甚至像数据库操作那样的like运算符,这里就不一一列举了
- BOOL tmp1=[predicate1 evaluateWithObject:human];//验证谓词是否成立,得到布尔返回值
- BOOL tmp2=[predicate2 evaluateWithObject:human];
- if (tmp1) {
- NSLog(@"human对象的name属性为'holydancer'");
- }
- if (tmp2) {
- NSLog(@"human对象的child属性的age为5");
- }
- }
- return 0;
- }
2012-03-21 19:59:42.668 predicate[2246:403] human对象的name属性为'holydancer'
2012-03-21 19:59:42.670 predicate[2246:403] human对象的child属性的age为5
灵活多变,我们暂且掌握到这里便足够了。另外,到今天为止,我们的objective-c基础就告一段落了,马上我要推出IPhone开发的教学
博客,希望大家继续关注。如果我之前的博客有什么错误的地方或者不够清楚的,可以评论告诉我,最后,感谢关注。
NSPredicate,谓词的更多相关文章
- NSPredicate谓词
NSPredicate——谓词(is) 作用:判断条件表达式的求值返回真或假的过程 使用步骤: . 定义NSPredicate对象并指定条件 . 调用谓词的evaluateWithObject方法判断 ...
- objective-c中使用cocoa的NSPredicate,谓词(十四)
holydancer原创,如需转载,请在显要位置注明: 转自holydancer的CSDN专栏,原文地址:http://blog.csdn.net/holydancer/article/details ...
- IOS开发之NSPredicate谓词的用法
编程的人员不管是上过大学还是从培训机构出来的或做后台的.前端的都应该SQL语句有所了解,我们知道,在SQL语句当中 where 条件表达式可以对二维关系表的数据做条件筛选.微软的C# .net中也实现 ...
- NSPredicate 谓词总结 数组过滤 模糊匹配
NSPredicate 用于指定过滤条件,主要用于从集合中分拣出符合条件的对象,也可以用于字符串的正则匹配. NSPredicate常用方法介绍 1.创建NSPredicate(相当于创建一个过滤条件 ...
- NSPredicate谓词查询
Cocoa提供了一个类NSPredicate类,该类主要用于指定过滤器的条件,该对象可以准确的描述所需条件,对每个对象通过谓词进行筛选,判断是否与条件相匹配.谓词表示计算真值或假值的函数. NSPre ...
- NSPredicate谓词的用法
在IOS开发Cocoa框架中提供了一个功能强大的类NSPredicate,下面来讨论一下它的强大之处在哪...NSPredicate继承自NSObject,它有两个派生的子类• NSCompariso ...
- NSPredicate
NSPredicate 1. 正则表达式使用单个字符串来描述.匹配一系列符合某个句法规则的字符串.通常被用来检索.替换那些符合某个模式的文本. 2. iOS中正则使用 有三种(NSPredicate, ...
- NSPredicate的使用
简述 NSPredicate谓词条件过滤器,一般用于过滤数组数据,原理和用法都类似于SQL中的where,作用相当于数据库的过滤取. 常用函数 创建谓词 + (NSPredicate *)predic ...
- NSPredicate 的使用(持续更新)
NSPredicate 谓词工具一般用于过滤数组数据,也可用来过滤CoreData查询出的数据. 1). 支持keypath 2). 支持正则表达式 在使用之前先新建3个类 Teacher Info ...
随机推荐
- Avoiding PostgreSQL database corruption
TL;DR: Don't ever set fsync=off, don't kill -9 the postmaster then deletepostmaster.pid, don't run P ...
- Python面向对象编程——引言
1.类和实例:类是对象的定义,而实例是真正的事物.他存放了类中所定义的对象的具体信息 关键字是class,后面紧跟着一个类名,随后是定义类的雷替代码.通常有各种各样的定义和声明组成. class ...
- jQuery easyui datagrid数据绑定
1.绑定json数据 <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type&qu ...
- bash内部命令-2
http://www.gnu.org/software/bash/ http://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/ [root@250-shiyan ~]# ...
- Openjudge计算概论-DNA排序
/*===================================== DNA排序 总时间限制: 1000ms 内存限制: 65536kB 描述 给出一系列基因序列,由A,C,G,T四种字符组 ...
- windows下做react native官方例子遇到的问题
1.android/app/build.gradle文件中,指定了版本: compileSdkVersion 23buildToolsVersion "23.0.1" 需要在设置中 ...
- Python基础(三)——集合、有序 无序列表、函数、文件操作
1.Set集合 class set(object): """ set() -> new empty set object set(iterable) -> n ...
- 关于iis站点无法读取 服务器共享目录的问题
也是权限问题,具体解决方法如下: 1. 找到该站点所在的应用程序池>>高级设置>>进程模型>>设置标志账号,如下图所示 2. 设置账号之后,找到该共享目录>& ...
- bzoj1803: Spoj1487 Query on a tree III
Description You are given a node-labeled rooted tree with n nodes. Define the query (x, k): Find the ...
- linux下查看进程运行的时间
原文链接:http://www.centoscn.com/CentOS/2014/0403/2724.html 可通过ps 来查看,通过参数 -o 来查看 例: ps -eo pid,tty,user ...