Contents

formUnion(_:)

Inserts the elements of the given sequence into the set.

Declaration

mutating func formUnion<S>(_ other: S) where Element == S.Element, S : Sequence

Parameters

  • other:

    A sequence of elements. other must be finite.

Discussion

If the set already contains one or more elements that are also in other, the existing members are kept. If other contains multiple instances of equivalent elements, only the first instance is kept.

var attendees: Set = ["Alicia", "Bethany", "Diana"]
let visitors = ["Diana", "Marcia", "Nathaniel"]
attendees.formUnion(visitors)
print(attendees)
// Prints "["Diana", "Nathaniel", "Bethany", "Alicia", "Marcia"]"

See Also

Combining Sets