osx - Swift 2.1: Removing duplicates from an array of structs? -


i have array of structs (the struct has nothing in strings guess have used array of arrays of strings thought might want add non-string elements later).

    struct ensrow {         var adlastname: string = ""         var admaidenname: string = ""         var adfirstname: string = ""         var adage: string = ""         var adlocation: string = ""         var addeathdate: string = ""         var adpubdate: string = ""         var adpubdate2: string = ""         var adpubdate3: string = ""         var adobitdate: string = ""         var adobitdate2: string = ""         var adobitdate3: string = ""         var adsource: string = ""         var adsection: string = ""         var adpage: string = ""         var adphotoavailable: string = ""         var adudf1: string = ""         var adudf2: string = ""         var adudf3: string = ""         var adnotes: string = ""         var adfrom: string = ""     }     var ensarray: [ensrow] = [] 

i need remove duplicates efficiently either fill array or after it's filled. thought maybe set set objects if can make them hashable (not sure how) , if there conditional way add members set. however, ideally last property (adfrom) variable while still removing structs duplicates in other properties. suggestions how best this? thanks!

this seems work - kind of brute force , rather slow, but...

struct ensrow:equatable {     var adlastname: string = ""     var admaidenname: string = ""     var adfirstname: string = ""     var adage: string = ""     var adlocation: string = ""     var addeathdate: string = ""     var adpubdate: string = ""     var adpubdate2: string = ""     var adpubdate3: string = ""     var adobitdate: string = ""     var adobitdate2: string = ""     var adobitdate3: string = ""     var adsource: string = ""     var adsection: string = ""     var adpage: string = ""     var adphotoavailable: string = ""     var adudf1: string = ""     var adudf2: string = ""     var adudf3: string = ""     var adnotes: string = ""     var adfrom: string = "" }  func ==(lhs: ensrow, rhs: ensrow) -> bool {     if lhs.adlastname != rhs.adlastname {         return false     }     return lhs.adlastname == rhs.adlastname         && lhs.admaidenname == rhs.admaidenname         && lhs.adfirstname == rhs.adfirstname         && lhs.adage == rhs.adage         && lhs.adlocation == rhs.adlocation         && lhs.addeathdate == rhs.addeathdate         && lhs.adpubdate == rhs.adpubdate         && lhs.adpubdate2 == rhs.adpubdate2         && lhs.adpubdate3 == rhs.adpubdate3         && lhs.adobitdate == rhs.adobitdate         && lhs.adobitdate2 == rhs.adobitdate2         && lhs.adobitdate3 == rhs.adobitdate3         && lhs.adsource == rhs.adsource         && lhs.adsection == rhs.adsection         && lhs.adpage == rhs.adpage         && lhs.adphotoavailable == rhs.adphotoavailable         && lhs.adudf1 == rhs.adudf1         && lhs.adudf2 == rhs.adudf2         && lhs.adudf3 == rhs.adudf3         && lhs.adnotes == rhs.adnotes } 

Comments