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

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

    Use NSArray filteredArrayUsingPredicate: method. Its really fast to find out similar types of object in both arrays

    NSPredicate *intersectPredicate = [NSPredicate predicateWithFormat:@"SELF IN %@", otherArray];
    NSArray *intersectArray = [firstArray filteredArrayUsingPredicate:intersectPredicate];
    

    From above code intersect array gives you same objects which are in other array.

提交回复
热议问题