Ich erhalte eine JSON-Daten und Anhängen an ein Tupel gibt es Duplikate in diesem Array gibt es eine Möglichkeit, ich kann sie entfernen? Hier ist, wie ich die json Daten bekommen und an die TupelSo entfernen Sie Duplikat aus Tupel
if let hru = ($0["Menu"]["title"]).string{
let uw = ($0["name"]).string
let tagloc = (tag: hru, location: uw)
self.resultTuples.append(tagloc)
}
Am Drucken des Tupels ähnliche
for var i = 0; i < self.resultTuples.count; ++i{
print(self.resultTuples[i])
}
Aber was gedruckt wird ist
tag: Rice Dishes
tag: Rice Dishes
tag: Cakes and Creams
tag: Cakes and Creams
tag: Cakes and Creams
tag: Pastries and Others
tag: Pastries and Others
tag: Pastries and Others
tag: Pastries and Others
tag: Pastries and Others
tag: Pastries and Others
tag: Pastries and Others
tag: Pastries and Others
tag: Pastries and Others
tag: Pastries and Others
tag: Soups and Sauces
tag: Soups and Sauces
....
ich entferne Einstellung alle Duplikate aus diesem Tupel
EDIT:
Array hat nicht funktioniert, ich habe ein Modell Menus
if let hru = ($0["Menu"]["title"]).string{
var men = Menus(nam: hru)
let set = NSSet(array: self.menus)
self.menus = set.allObjects as! [Menus]
self.menus.append(men)
}
for i in self.menus{
print("MENUSS \(i.name)")
}
Mögliche Duplikat [Entfernen Sie doppelte Objekte in einem Array] (http://stackoverflow.com/questions/34709066/remove-duplicate-objects-in-an-array) – dfri
Dies ist ein Tupel – lordxx
Ich habe gerade überprüft :/sadly tuple ist kein Objekt, funktioniert nicht mit AnyObject, also kann man es nicht in Set oder NSSet umwandeln, ich denke Tupel hat ziemlich die eingeschränkte Funktion, also schlage ich vor, dass man Struct oder Class verwendet, dann wird es besser, Refactor zu Struct wie unten Antwort bereitgestellt – Tj3n