---
title: "union(_:)"
framework: swift
role: symbol
role_heading: Instance Method
path: "swift/set/union(_:)"
---

# union(_:)

Returns a new set with the elements of both this set and the given sequence.

## Declaration

```swift
func union<S>(_ other: S) -> Set<Element> where Element == S.Element, S : Sequence
```

## Parameters

- `other`: A sequence of elements. other must be finite.

## Return Value

Return Value A new set with the unique elements of this set and other.

## Discussion

Discussion In the following example, the attendeesAndVisitors set is made up of the elements of the attendees set and the visitors array: let attendees: Set = ["Alicia", "Bethany", "Diana"] let visitors = ["Marcia", "Nathaniel"] let attendeesAndVisitors = attendees.union(visitors) print(attendeesAndVisitors) // Prints "["Diana", "Nathaniel", "Bethany", "Alicia", "Marcia"]" 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. let initialIndices = Set(0..<5) let expandedIndices = initialIndices.union([2, 3, 6, 6, 7, 7]) print(expandedIndices) // Prints "[2, 4, 6, 7, 0, 1, 3]"

## See Also

### Combining Sets

- [formUnion(_:)](swift/set/formunion(_:).md)
- [intersection(_:)](swift/set/intersection(_:)-1zh8f.md)
- [intersection(_:)](swift/set/intersection(_:)-6uts9.md)
- [formIntersection(_:)](swift/set/formintersection(_:).md)
- [symmetricDifference(_:)](swift/set/symmetricdifference(_:).md)
- [formSymmetricDifference(_:)](swift/set/formsymmetricdifference(_:)-22p0m.md)
- [formSymmetricDifference(_:)](swift/set/formsymmetricdifference(_:)-5u38b.md)
- [subtract(_:)](swift/set/subtract(_:)-8gc48.md)
- [subtract(_:)](swift/set/subtract(_:)-7cd3y.md)
- [subtracting(_:)](swift/set/subtracting(_:)-3n4lc.md)
- [subtracting(_:)](swift/set/subtracting(_:)-2qge3.md)
