Check duplicate property values of objects in NSArray

前端 未结 4 1868
北海茫月
北海茫月 2021-01-16 07:37

I have an NSArray containing objects with a size property.

How can I check if the NSArray has two objects with the same value

4条回答
  •  佛祖请我去吃肉
    2021-01-16 08:15

    NSArray *cleanedArray = [[NSSet setWithArray:yourArraywithDuplicatesObjects ] allObjects];
    

    Use Sets this will remove all duplicates objects.Will return NSArrayNSCountedSet and use countForObject: method to find out how often each object appears how many times.

提交回复
热议问题