<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.10.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/Set/intersection(_:)-6uts9",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:Sh12intersectionyShyxGqd__7ElementQyd__RszSTRd__lF"
  },
  "title" : "intersection(_:)"
}
-->

# intersection(_:)

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

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

## Parameters

`other`

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

## Return Value

A new set.

## 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 = ["Bethany", "Eric", "Forlani", "Greta"]
let bothNeighborsAndEmployees = employees.intersection(neighbors)
print(bothNeighborsAndEmployees)
// Prints "["Bethany", "Eric"]"
```

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)