过滤自定义对象的NSArray

过滤自定义对象的NSArray

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

问题描述

我有一个 c

What I want to do is create a new NSArray from the existing contacts array that match the userIDs in userIDs.

因此,如果联系人有3 userID 1,2和3.我的 userIDs 有一个 NSString 我想让结果数组包含 Contact ,它等于 userID 3.

So if contacts has 3 Contact objects with userID 1,2 and 3. And my userIDs has a NSString object 3. Then I want the resulting array to contain Contact which equals userID 3.

Contact.h

Contact.h

Contact : NSObject

FacebookGroup.h

FacebookGroup : Contact

@property (nonatomic, strong) NSSet *individuals;

Individual.h

Individual : Contact

@property (nonatomic, strong) NSString *userID;


推荐答案

这是您要查找的内容吗?

Is this what you are looking for?

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"userID IN %@", userIDs];
NSArray *filtered = [contacts filteredArrayUsingPredicate:predicate];

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

08-14 14:31