Returns a new set with the elements that are either in this set or in the given sequence, but not in both.
SDK
- Xcode 10.2+
Framework
- Swift Standard Library
Declaration
Parameters
otherA sequence of elements.
othermust be finite.
Return Value
A new set.
Discussion
In the following example, the either set is made up of the elements of the employees and neighbors sets that are not in both employees and neighbors. In particular, the names "Bethany" and "Eric" do not appear in either.
let employees: Set = ["Alicia", "Bethany", "Diana", "Eric"]
let neighbors = ["Bethany", "Eric", "Forlani"]
let eitherNeighborsOrEmployees = employees.symmetricDifference(neighbors)
print(eitherNeighborsOrEmployees)
// Prints "["Diana", "Forlani", "Alicia"]"