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

# union(_:)

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

## Declaration

```swift
func union(_ other: Self) -> Self
```

## Parameters

- `other`: A set of the same type as the current set.

## 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 and visitors sets: 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. let initialIndices = Set(0..<5) let expandedIndices = initialIndices.union([2, 3, 6, 7]) print(expandedIndices) // Prints "[2, 4, 6, 7, 0, 1, 3]" note: If this set and other contain elements that are equal but distinguishable (e.g. via ===), which of these elements is present in the result is unspecified.

## See Also

### Combining Sets

- [formUnion(_:)](swift/setalgebra/formunion(_:).md)
- [intersection(_:)](swift/setalgebra/intersection(_:).md)
- [formIntersection(_:)](swift/setalgebra/formintersection(_:).md)
- [symmetricDifference(_:)](swift/setalgebra/symmetricdifference(_:).md)
- [formSymmetricDifference(_:)](swift/setalgebra/formsymmetricdifference(_:).md)
