Anand Anand - 4 years ago 1283
Swift Question

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;
}

Answer Source

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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download