The method of iOS array deduplication

//Recently discovered a newly discovered array to deduplicate, no need to loop, just one line of code
// remove duplicates from the array
     NSArray *oldArr = @[@"1",@"2",@"3",@"4",@"5",@"6",@"2",@"3"];
     NSArray *newarr = [oldArr valueForKeyPath:@"@distinctUnionOfObjects.self"];
     NSLog(@"%@",newarr);

Leave a Reply

Your email address will not be published. Required fields are marked *

en_USEnglish