比較兩個數(shù)組,并除去相同元素,正常情況兩個for循環(huán),這樣代碼不美觀,而且效率不夠高!今天get到一個新方法;
NSArray * arr1 = @[@1,@2,@3];
NSArray * arr2 = @[@2,@3,@4,@5];
NSPredicate * filterPredicate = [NSPredicate predicateWithFormat:@"NOT (SELF IN %@)",arr1];
NSArray * filter = [arr2 filteredArrayUsingPredicate:filterPredicate];
NSLog(@"%@",filter);
排序之后的結(jié)果是 @[@"4",@"5"];