比较两个数组,并除去相同元素,正常情况两个for循环,这样代码不美观,而且效率不够高!今天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);
排序之后的结果是 @[@"4",@"5"];