intersectionWith(_ arrays: [Element]..., comparator:(Element, Element) -> Bool) -> [Element]

This method is like .intersection except that it accepts comparator which is invoked to compare elements of arrays.

Parameters

  • arrays: The arrays to inspect.
  • comparator: The comparator invoked per element.

Returns

Returns the new array of shared values.

func compare(obj1:[String:Int], obj2:[String:Int]) -> Bool {
    return obj1["x"] == obj2["x"] && obj1["y"] == obj2["y"]
}
let objects1 = [["x":1, "y":2], ["x":2, "y":1]]
let objects2 = [["x":1, "y":1], ["x":1, "y":2]]
// -> [["x":1, "y":2]]