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 ...
随机推荐
- php特殊语法--模板引擎中比较常见
<?php $a=array(1,2,0); foreach ($a as $v): if($v>1): ?> 5 <?php endif; endforeach; ?> ...
- html之label标签
label标签为input元素定义标注,label标签与相关元素通过id属性绑定在一起. 相关属性: for:规定label绑定到哪个表单元素 form:规定label字段所属的一个或多个表单 示例代 ...
- javascript中单体模式的实现
单体模式作为一种软件开发模式在众多面向对象语言中得到了广泛的使用,在javascript中,单体模式也是使用非常广泛的,但是由于javascript语言拥有其独特的面向对象方式,导致其和一些传统面向对 ...
- 查询oracle RAC实例名称等信息
select * from gv$instance;
- zookeeper Keepalived
ZooKeeper是一个分布式的,开放源码的分布式应用程序协调服务,是Google的Chubby一个开源的实现,是Hadoop和Hbase的重要组件.它是一个为分布式应用提供一致性服务的软件,提供的功 ...
- Hibernate常用配置文件详解
本文转载自:http://blog.csdn.net/csh624366188/article/details/7578939 初学hibernate的童鞋,刚开应该都有这种感觉,hibernate的 ...
- linux创建git远程仓库
root用户 ============================ // 创建用户 >adduser newuser // 修改用户的密码 >passwd newuser // 设置权 ...
- VBA 按照文件类型名称打开一个文件
Application.GetOpenFilename(fileFilter, fileIndex, fileSelectTitle, button, False) fileFilter: 指定能够被 ...
- 04文件与IO
文件系统调用: open.close.create.read.write open: int open(const char* path, int flags) path:要打开的文件的路径 flag ...
- Redis集群方案介绍
由于Redis出众的性能,其在众多的移动互联网企业中得到广泛的应用.Redis在3.0版本前只支持单实例模式,虽然现在的服务器内存可以到100GB.200GB的规模,但是单实例模式限制了Redis没法 ...