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

前端 未结 9 1812
说谎
说谎 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:52

    Try this way;

    NSArray *mainArray=@[@"A",@"B",@"C",@"D"];
    NSArray *myArray=@[@"C",@"x"];
    
    BOOL result=YES;
    for(id object in myArray){
        if (![mainArray containsObject:object]) {
            result=NO;
            break;
        }
    }
    NSLog(@"%d",result); //1 means contains, 0 means not contains
    

提交回复
热议问题