title: Swift removing duplicate from array of object
body: <p>I try to append json data that I got from my server to array of object and want to remove any duplicate if there is any</p>
  
  <p>this is my custom class</p>
  
  <pre><code>class datastruct {
  
      var id: Int?
      var name: String?
  
      init(add: NSDictionary) {
          id = add["id"] as? Int
          name = add["name"] as? String
      }
  }
  </code></pre>
  
  <p>and this is my code that I use to append json to my array</p>
  
  <pre><code>    var data:Array&lt; datastruct &gt; = Array &lt; datastruct &gt;()
      Alamofire.request(url)
                  .responseJSON{ response in
                      switch response.result {
                      case .success(let JSON):
                          if let list = JSON as? NSArray {
                              for i in 0 ..&lt; list.count {
                                  if let res = list[i] as? NSDictionary {
                                      self.data.append(datastruct(add: res))
                                  }
                              }
                              self.refresh()
                          }
  
                      case .failure(let error):
  
                      }
  
                  }
  </code></pre>
  
  <p>the problem is I already search several solution to remove any duplicate array in stackoverflow</p>
  
  <p><a href="https://stackoverflow.com/questions/34709066/remove-duplicate-objects-in-an-array">Remove duplicate objects in an array</a></p>
  
  <p><a href="https://stackoverflow.com/questions/34142463/remove-duplicates-from-array-of-objects">Remove duplicates from array of objects</a></p>
  
  <p><a href="https://stackoverflow.com/questions/39307188/removing-duplicates-from-array-of-custom-objects-swift">Removing Duplicates From Array of Custom Objects Swift</a></p>
  
  <p>but I when I try to use <code>Hashable</code> I don't know where to put <code>Set</code> to my code because it is <code>NSDictionary</code></p>
  
  <p>Please help me how to remove duplicate of array or give me some hint</p>