.isSuperset()

MarkDavidHalstead's avatar
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.

Syntax

setOne.isSuperset(of: setTwo)

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

Example

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

Contribute to Docs

Learn Swift on Codecademy