In addition to set manipulation methods, we have a number of methods to determine information about set membership.
Let's take a look at the following code:
let animalKingdom: Set<String> = ["dog", "cat", "pidgeon",
"chimpanzee", "snake", "kangaroo",
"giraffe", "elephant", "tiger",
"lion", "panther"]
let vertebrates: Set<String> = ["dog", "cat", "pidgeon",
"chimpanzee", "snake", "kangaroo",
"giraffe", "elephant", "tiger",
"lion", "panther"]
let reptile: Set<String> = ["snake"]
let mammals: Set<String> = ["dog", "cat", "chimpanzee",
"kangaroo", "giraffe", "elephant",
"tiger", "lion", "panther"]
let catFamily: Set<String> = ["cat", "tiger", "lion", "panther"]
let domesticAnimals: Set<String> = ["cat", "dog"]
print(mammals.isSubset(of: animalKingdom)) // true
print(mammals.isSuperset(of: catFamily)) // true
print(vertebrates.isStrictSubset(of: animalKingdom)) // false
print(mammals.isStrictSubset(of: animalKingdom)) // true
print(animalKingdom.isStrictSuperset(of: vertebrates)) // false
print(animalKingdom.isStrictSuperset(of: domesticAnimals)) // true
print(catFamily.isDisjoint(with: reptile)) // true
Now, let's look at how the preceding code functions.
The isSubset method will return true if all elements in the set that the method is called on are contained within the set passed as a parameter:
print(mammals.isSubset(of: animalKingdom)) // true
The following image depicts Set B as the subset of Set A:

This will also return true if the two sets are equal (contain the same elements). If you want a true value only if the set that the method is called on is a subset and not equal, then you can use isStrictSubset:
print(vertebrates.isStrictSubset(of: animalKingdom)) // false
print(mammals.isStrictSubset(of: animalKingdom)) // true
The isSuperset method will return true if all elements in the set passed as a parameter are within the set that the method is called on:
print(mammals.isSuperset(of: catFamily)) // true
The following image depicts Set A as the superset of Set B:

This will also return true if the two sets are equal (contain the same elements). If you want a true value only if the set that the method is called on is a superset and not equal, then you can use isStrictSuperset:
print(animalKingdom.isStrictSuperset(of: vertebrates)) // false
print(animalKingdom.isStrictSuperset(of: domesticAnimals)) // true
The isDisjoint method will return true if there are no common elements between the set that the method is called on and the set passed as a parameter:
print(catFamily.isDisjoint(with: reptile)) // true
The following image shows that Set A and Set B are disjoint:

As with arrays, a set can be declared immutable by assigning it to a let constant instead of a var variable:
let planets: Set<String> = ["Mercury", "Venus", "Earth",
"Mars", "Jupiter", "Saturn",
"Uranus", "Neptune", "Pluto"]
planets.remove("Pluto") // Doesn't compile
This is because a set, like the other collection types, is a value type. Removing an element would mutate the set, which creates a new copy, but a let constant can't have a new value assigned to it, so the compiler prevents any mutating operations.