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

# formUnion(_:)

Adds the elements of the given set to the set.

## Declaration

```swift
mutating func formUnion(_ other: Self)
```

## Parameters

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

## Discussion

Discussion In the following example, the elements of the visitors set are added to the attendees set: var attendees: Set = ["Alicia", "Bethany", "Diana"] let visitors: Set = ["Diana", "Marcia", "Nathaniel"] attendees.formUnion(visitors) print(attendees) // 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. var initialIndices = Set(0..<5) initialIndices.formUnion([2, 3, 6, 7]) print(initialIndices) // Prints "[2, 4, 6, 7, 0, 1, 3]"

## See Also

### Combining Sets

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