使用自定义对象属性过滤数组 [英] Filter array using custom object property

查看:118
本文介绍了使用自定义对象属性过滤数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个对象数组。每个对象都有自己的属性(name,desc,status)。 name desc NSString status BOOL

I have an array of objects.Each object has its own properties (name, desc, status). name and desc are NSString and status is BOOL.

我想通过status属性过滤此数组。例如:使用 status == YES 获取所有对象。

I want to filter this array by status property. Ex: Get all objects with status == YES.

我如何实现这一目标?

推荐答案

尝试使用NSPredictate

Try use NSPredictate

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"status = %@", @"YES"];
NSArray *filterArray = [array filteredArrayUsingPredicate:predicate];

这将为您提供一个数组,其中所有对象的状态均为YES。

This gives you an array with all object where status is equal YES.

这篇关于使用自定义对象属性过滤数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆