简述:Cocoa框架中的NSPredicate用于查询,原理和用法都类似于SQL中的where,作用相当于数据库的过滤取。
实践成功的一个小例子
NSPredicate *predicate = [NSPredicate predicateWithFormat:@“%@ CONTAINS ‘image’”,self.managers.img];
if( [predicate evaluateWithObject:self.managers.img] )
如果包含image,则判断为真,反之为假
定义(最常用到的方法):
[cpp]
view plain
copy
- NSPredicate *ca = [NSPredicate predicateWithFormat:(NSString *), ...];
比较运算符>,<,==,>=,<=,!=
可用于数值及字符串
例:@"number > 100"
字符串本身:SELF
例:@“SELF == ‘APPLE’"