Removes the elements of the set that aren’t also in the given sequence.
SDK
- Xcode 8.3+
Framework
- Swift Standard Library
Declaration
mutating func formIntersection<S>(_ other: S) where Element == S.Element, S : Sequence
Parameters
otherA sequence of elements.
othermust be finite.
Discussion
In the following example, the elements of the employees set that are not also members of the neighbors set are removed. In particular, the names "Alicia", "Chris", and "Diana" are removed.
var employees: Set = ["Alicia", "Bethany", "Chris", "Diana", "Eric"]
let neighbors = ["Bethany", "Eric", "Forlani", "Greta"]
employees.formIntersection(neighbors)
print(employees)
// Prints "["Bethany", "Eric"]"