Published Nov 22, 2022
Contribute to Docs

The .isSuperset() method returns a boolean telling whether every element of a given set exists in another set.


setOne.isSuperset(of: setTwo)

The .isSuperset() method returns true if setOne is a superset of setTwo, false otherwise.


In the following example, the .isSuperset() method is used with a conditional expression to print a phrase:

let setOne: Set = ["Apple", "Orange", "Banana", "Kiwi", "Tomato"]
let setTwo: Set = ["Orange", "Banana"]
if setOne.isSuperset(of: setTwo) {
print("setOne is a superset of setTwo.")
} else {
print("setOne is not a superset of setTwo.")

This will output the following:

setOne is a superset of setTwo.

All contributors

Looking to contribute?

Learn Swift on Codecademy