Finding Intersection of NSMutableArrays

前端 未结 5 1906
广开言路
广开言路 2020-11-28 09:30

I have three NSMutableArray containing names that are added to the lists according to different criterieas.

Here are my arrays pseudocode:

NSMutableA         


        
5条回答
  •  眼角桃花
    2020-11-28 10:32

    NSMutableArray *first = [[NSMutableArray alloc] initWithObjects:@"Jack", @"John", @"Daniel", @"Lisa",nil];
    
    NSMutableArray *seconds =[[NSMutableArray alloc] initWithObjects:@"Jack", @"Bryan", @"Barney", @"Lisa",@"Penelope",@"Angelica",nil];
    
    NSMutableArray *third = [ [ NSMutableArray alloc]init];
    
    
    for (id obj in first) {
    
        if ([seconds  containsObject:obj] ) {
    
    
            [third addObject:obj];
    
        }
    
    
    }
    
    
    NSLog(@"third is : %@ \n\n",third);
    

    OUTPUT:

    third is : (

    Jack,
    
    Lisa
    

    )

提交回复
热议问题