Check that the contents of one NSArray are all in another array

前端 未结 9 1782
说谎
说谎 2020-12-10 08:28

I have one NSArray with names in string objects like this:@[@\"john\", @\"smith\", @\"alex\", @\"louis\"], and I have another array that contains

9条回答
  •  离开以前
    2020-12-10 08:47

    Use this code..

    NSArray *temp1 = [NSArray arrayWithObjects:@"john",@"smith",@"alex",@"loui,@"Jac", nil];
    NSArray *temp2 = [NSArray arrayWithObjects:@"john",@"smith",@"alex",@"loui,@"Rob", nil];
    
    NSMutableSet *telephoneSet = [[NSMutableSet alloc] initWithArray:temp1] ;
    NSMutableSet *telephoneSet2 = [[NSMutableSet alloc] initWithArray:temp2];
    
    
    [telephoneSet intersectSet:telephoneSet2];
    
     NSArray *outPut = [telephoneSet allObjects];
     NSLog(@"%@",outPut);
    

    output array contains:

    "john","smith","alex","loui
    

    as per your requirement.

提交回复
热议问题