Removes the elements of the set that are also in the given sequence and adds the members of the sequence that are not already in the set.
SDK
- Xcode 10.2+
Framework
- Swift Standard Library
Declaration
mutating func formSymmetricDifference(_ other: Set<Element>)
Parameters
otherAnother set.
Discussion
In the following example, the elements of the employees set that are also members of neighbors are removed from employees, while the elements of neighbors that are not members of employees are added to employees. In particular, the names "Alicia", "Chris", and "Diana" are removed from employees while the names "Forlani" and "Greta" are added.
var employees: Set = ["Alicia", "Bethany", "Chris", "Diana", "Eric"]
let neighbors: Set = ["Bethany", "Eric", "Forlani", "Greta"]
employees.formSymmetricDifference(neighbors)
print(employees)
// Prints "["Diana", "Chris", "Forlani", "Alicia", "Greta"]"