iOS 查询数组中的对象 谓词NSPredicate
2016-08-05 14:21
651 查看
1.NSString 对象
NSArray *array =@["123", @"234" , @"345"];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF contains [cd] %@", "2"];
NSArray *filterdArray = [array filterdArrayUsingPredicate:predicate];
NSLog(@"%@", filterdArray );
//output : @"123", "234"
2.含有属性的对象
@interface Person: NSObject
{
NSString *_name;
NSString *_telephone;
NSInteger _id;
}
@property (nonatomic, copy) NSString *name;
@property (nonatomic, copy) NSString *telephone;
@property (nonatomic, assign) NSInteger id;
@end
//
1).等于查询
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"name == %@", "Ansel"];
NSArray *filteredArray = [array filteredArrayUsingPredicate:predicate];
2).模糊查询
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"name CONTAINS %@", @"A"]; //predicate只能是对象
NSArray *filteredArray = [array filteredArrayUsingPredicate:predicate];
NSArray *array =@["123", @"234" , @"345"];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF contains [cd] %@", "2"];
NSArray *filterdArray = [array filterdArrayUsingPredicate:predicate];
NSLog(@"%@", filterdArray );
//output : @"123", "234"
2.含有属性的对象
@interface Person: NSObject
{
NSString *_name;
NSString *_telephone;
NSInteger _id;
}
@property (nonatomic, copy) NSString *name;
@property (nonatomic, copy) NSString *telephone;
@property (nonatomic, assign) NSInteger id;
@end
//
1).等于查询
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"name == %@", "Ansel"];
NSArray *filteredArray = [array filteredArrayUsingPredicate:predicate];
2).模糊查询
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"name CONTAINS %@", @"A"]; //predicate只能是对象
NSArray *filteredArray = [array filteredArrayUsingPredicate:predicate];
相关文章推荐
- iOS 开发NSPredicate,谓词过滤。用于搜索、查询。
- iOS 谓词查询NSPredicate
- iOS 谓词查询NSPredicate
- 【iOS开发技术】NSPredicate谓词的用法 数组过滤
- iOS 查询数组中的对象
- iOS 查询数组中的对象
- iOS---NSPredicate谓词的用法 数组过滤
- IOS学习 NSOperation cell存储图片思路 沙盒路径查找 数组中添加空对象 block循环引用风险
- ci操作mysql,查询结果集返回 给对象或者数组
- iOS NSKeyedArchiver序列化 存储数组对象
- iOS NSPredicate 查询、搜索, 各种验证, 正则表达式
- iOS字典对象和数组对象转成json
- ios 学习之 NSPredicate 模糊、精确、查询
- iOS对象(字典或数组)转化为JSon字符串
- iOS:转载:IOS谓词--NSPredicate
- iOS遍历数组相同值元素到另一数组中同一对象的子数组
- 【Objective-C高级编程】iOS与OS X多线程和内存管理(八) __block 从栈上复制到堆 截获对象 数组
- ios 学习之 NSPredicate 模糊、精确、查询 ,包括模糊搜索,多条件搜索,及属性中多个字段检索
- ios NSPredicate用于两个数组筛选
- laravel中将查询的对象转换为多维数组的函数