Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to remove Duplicate values from Dict in swift 2.0

Hi I just want remove repeated objects should be removed in dictionary I am populating it in tableView

Here my sample code in 'CellForRowAtIndexPath'

controller.titleName = dict["itemName"] as? String

my output:

{
    itemName = test;
},
{
    itemName = funny;
},
    {
    itemName = vv;
},
    {
    itemName = hhh;
},
    {
    itemName = west;
}
like image 307
Anand Avatar asked Jan 27 '26 02:01

Anand


2 Answers

First, i think thing you are using array to make dict so before load tableview/collectionview delete all replicated object from your array.

There is one option you have to create NSSet from NSArray so in NSSet all replicated object automatically removed . and then from NSSet you have to create NSArray. convert set from array as follow

var set = NSSet(array: myarray)

To convert array for set

var newarry = set.allObjects as NSArray
like image 191
Jaydeep Patel Avatar answered Jan 29 '26 19:01

Jaydeep Patel


Just try this

let uniqueArr = Array(Set(dict.values))
like image 20
Rashwan L Avatar answered Jan 29 '26 20:01

Rashwan L



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!