1

オブジェクトの があり、NSArrayContact呼ぶことができますcontacts。Contact はスーパークラスでFacebookGroupありIndividual、のサブクラスですContact。オブジェクトのセットであるFacebookGroupというプロパティがあります。individualsIndividual

オブジェクトのもありNSArrayます。NSStringこれを と呼ぶことができますuserIDs

私がしたいのは、のユーザーIDに一致NSArrayする既存の配列から新しいを作成することです。contactsuserIDs

したがって、ifには1、2、および3 のcontacts3 つのContactオブジェクトがあり、myにはオブジェクト 3 があります。次に、結果の配列に3に等しいものが含まれるようにします。userIDuserIDsNSStringContactuserID

Contact.h

Contact : NSObject

FacebookGroup.h

FacebookGroup : Contact

@property (nonatomic, strong) NSSet *individuals;

個人.h

Individual : Contact

@property (nonatomic, strong) NSString *userID;
4

3 に答える 3

4
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"userId = %@", myContact.userId];
NSArray *filteredArray = [contacts filteredArrayUsingPredicate:predicate];
于 2013-05-03T11:13:30.907 に答える