How to get unique values based on dictionary key, which is an element of an array in objective C ?
for example:
i am having an array of an Items
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 unique ItemCategory , not duplicates. If i can write [[aryItem objectatInde开发者_如何学编程x:i] valueForKey:ItemCategory] i get all categories, same category also included in this. I need only unique categories. I have an option searching whole array and then get unique Itemcategory objects, but i am looking for any short way to accomplish the same thing.
Thanks.
I think NSSet class is most suitable to collect unique values. You can create it using something like:
NSSet* categories = [NSSet setWithArray: [aryItem valueForKey: @"ItemCategory"]];
精彩评论