在一个数组里找到我想要的,类似select,过滤数组吧

来源:互联网 发布:大数据营销就业前景 编辑:程序博客网 时间:2024/06/11 13:35

其实就是NSPredicate,首先我先把我想要的条件注入NSPredicate里,然后再把数组跟着这个NSPredicate过滤一遍。

代码如下:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"uid == %@", @"11"]; NSArray *filteredArray = [memArr filteredArrayUsingPredicate:predicate];
过滤出来的就是uid等于11的,对,它可以过滤咱们自定义的实体的,就像是在字典里面,简直不要太方便

那要是纯粹的字符集合呢?

那就酱

[NSPredicate predicateWithFormat:@"SELF=='查询的字符串'"];
这个和数据库通用语法还挺像的,确实。

0 0