I have an array that looks like this:
var persons = [Person]()
And a person contains this:
id : Int
name : String
age : Int
gender : String
In my persons list I have multiple persons, but how do I sort this list on unique names?
I found this let unique = Array(Set(originals))
but it does not seem to work on a list of objects, I want to keep all the information of the object.
If my list contains these rows:
Adam, Adam, John, John, Michael, Nick, Tony
I only want to show:
Adam, John, Michael, Nick Tony
And I still want to be able to get Adams age for example.
Any ideas?
Edit
Person declaration
import Foundation
public class Person : NSObject {
var id = ""
var name = ""
var age = 0
var gender = ""
}
func ==(lhs: Person, rhs: Person) -> Bool {
return lhs.name == rhs.name
}