Value of my NSArray
includes the duplicates.
I find the duplicates but now how can I find the no. they repeat?
You can use NSCountedSet
for this. Add all your objects to a counted set, then use the countForObject:
method to find out how often each object appears.
Example:
NSArray *names = [NSArray arrayWithObjects:@"John", @"Jane", @"John", nil];
NSCountedSet *set = [[NSCountedSet alloc] initWithArray:names];
for (id item in set) {
NSLog(@"Name=%@, Count=%lu", item, (unsigned long)[set countForObject:item]);
}
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