I have an NSArray which contains a few duplicate objects. I want to print which objects are getting duplicated, for example:
NSArray * array = [NSArray arrayWithObjects: A, B, C, A, B];
Now I want to print in my console A
& B
as these are duplicated.
How do I do this?
You can use NSCountedSet
for this. you can add all the objects in a counted set, then use the countForObject
: method to find out how often each object appears. read about NSCountedSet for further reference
Use an NSCountedSet and only print the elements that returns a number>1 for countForObject:
method
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With