objective c - Check duplicate property values of objects in NSArray -
i have nsarray
containing objects size
property.
how can check if nsarray
has 2 objects same value size
?
can like:
int = 0; (id item1 in myarray) { nsdecimalnumber *size1 = [item1 size]; (id item2 in myarray) { nsdecimalnumber *size2 = [item2 size]; if ([size1 isequal:size2]) { ++; } } } if (i > [myarray count]) { nslog(@"duplicate sizes exist"); }
or there easier way?
use nscountedset. add objects counted set, , use countforobject
: method find out how each object appears in array.
you can check link how-to-find-duplicate-values-in-arrays
hope helps you
Comments
Post a Comment