What output will be produced by the code below?

var spaceships1 = Set<String>()

let spaceships2 = spaceships1

if spaceships1.isSubset(of: spaceships2) {
    print("This is a subset")
} else {
    print("This is not a subset")


Correct answer: "This is a subset".

Explanation: Sets distinguish between subsets and strict (or "proper") subsets, with the difference being that the latter necessarily excludes identical sets. That is, Set A is a subset of Set B if every item in Set A is also in Set B. On the other hand, Set A is a strict subset of Set B if every element in Set A is also in Set B, but Set B contains at least one item that is missing from Set A.


© 2017