Filter NSArray of custom objects

好久不见. 提交于 2019-11-28 14:24:04

Is this what you are looking for?

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

i'm expecting you want like this once see this one,

 NSMutableArray *names = [NSMutableArray arrayWithObjects:@"one", @"two", @"three", @"four", nil];
    NSMutableArray *ids = [NSMutableArray arrayWithObjects:@"1", @"2", @"2", @"3", nil];
    NSMutableArray *array=[[NSMutableArray alloc]init];
    for(int i=0;i<[ids count];i++){
       if([[ids objectAtIndex:i] isEqualToString:@"2"])
           [array addObject:[names objectAtIndex:i]];
    }
    NSLog(@"%@",array);

O/P:-

(
    two,
    three
)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!