How to get unique values ​​based on a dictionary key, which is an array element in a C object?

How to get unique values ​​based on a dictionary key, which is an array element in a C object?

eg:

I have an array of elements

aryItem

aryItem[0] = Dictionary{ ItemCategory ItemName ItemPrice } aryItem[1] = Dictionary{ ItemCategory ItemName ItemPrice } ........... ........... aryItem[n] = Dictionary{ ItemCategory ItemName ItemPrice } 

Now I want to get only a unique ItemCategory, not duplicates. If I can write [[aryItem objectatIndex: i] valueForKey: ItemCategory], I get all the categories, including the same category. I need only unique categories. I have the option of finding the whole array and then getting unique Itemcategory objects, but I'm looking for any short way to accomplish the same thing.

Thanks.

+4
source share
1 answer

I think the NSSet class is most suitable for collecting unique values. You can create it using something like:

 NSSet* categories = [NSSet setWithArray: [aryItem valueForKey: @"ItemCategory"]]; 
+6
source

All Articles