O'Reilly logo

Mastering Swift 4 - Fourth Edition by Jon Hoffman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Set operations

Apple has provided four methods that we can use to construct a set from two other sets. These operations can be performed in place, on one of the sets, or used to create a new set. These operations are as follows:

  • union and formUnion: These create a set with all the unique values from both sets
  • subtracting and subtract: These create a set with values from the first set that are not in the second set
  • intersection and fromIntersection: These create a set with values that are common to both sets
  • symmetricDifference and fromSymmetricDifference: These create a new set with values that are in either set, but not in both sets

Let's look at some examples and see the results that can be obtained from each of these operations. For ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required