How to check if two sets are identical in Swift? How to check if two sets are identical in Swift? swift swift

How to check if two sets are identical in Swift?


Set conforms to Equatable, so you can just do this:

if setA == setB {    ...}


"a set A is a subset of a set B, or equivalently B is a superset of A, if A is "contained" inside B, that is, all elements of A are also elements of B. A and B may coincide."

There fore you could check if A is a subset of B and vise versa.

let abcSet: Set = ["Chips", "Sandwiches", "Salad"]var foodSet = Set(["Salad", "Chips", "Sandwiches"])abcSet.isSubsetOf(foodSet); // truefoodSet.isSubsetOf(abcSet); // true