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

# intersection(_:)

Returns a new set with the elements that are common to both this set and the given set.

## Declaration

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

## Parameters

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

## Return Value

Return Value A new set.

## Discussion

Discussion In the following example, the bothNeighborsAndEmployees set is made up of the elements that are in both the employees and neighbors sets. Elements that are in only one or the other are left out of the result of the intersection. let employees: Set = ["Alicia", "Bethany", "Chris", "Diana", "Eric"] let neighbors: Set = ["Bethany", "Eric", "Forlani", "Greta"] let bothNeighborsAndEmployees = employees.intersection(neighbors) print(bothNeighborsAndEmployees) // Prints "["Bethany", "Eric"]" 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

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