使用谓词过滤不可变集合和可变集合的区别是:过滤不可变集合时,会返回符合条件的集合元素组成的新集合;过滤可变集合时,没有返回值,会直接剔除不符合条件的集合元素
NSPredicate* pred = [NSPredicatepredicateWithFormat:@"GoodsID != %ld",model.GoodsID];
[self.dataSource filterUsingPredicate:pred];
//self.dataSource过滤(删除goodsId==model.GoodsID)的实体
NSPredicate* testPred = [NSPredicatepredicateWithFormat:@"GoodsID ==%d",model.GoodsID];
NSArray* resultArray = [[NSArrayarrayWithArray:self.dataSource]filteredArrayUsingPredicate:testPred];
NSSLog(@"输出看下 resultArray--%@",resultArray);
//对于NSArray 里面的实体对象进行过滤并生成新的数组,数组里面存放的是实体model的description
iOS谓词的详细使用 :https://www.jianshu.com/p/88be28860cde
网友评论