differenceWith(_ values: [Element], comparator: (Element, Element) -> Bool) -> [Element]

This method is like difference except that it accepts comparator which is invoked to compare elements of array to values.

Parameters

  • values: The values to exclude.
  • comparator: The comparator invoked per element.

Returns

The new array of filtered values.

fileprivate func compare(obj1:[String:Int], obj2:[String:Int]) -> Bool {
    return obj1["x"] == obj2["x"] && obj1["y"] == obj2["y"]
}
[["x":1,"y":2], ["x":2, "y":1]].differenceWith([["x":1, "y":2]], comparator: compare)
// -> [["x":2, "y":1]]