<!--
{
  "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/formIntersection(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:Sh16formIntersectionyyqd__7ElementQyd__RszSTRd__lF"
  },
  "title" : "formIntersection(_:)"
}
-->

# formIntersection(_:)

Removes the elements of the set that aren’t also in the given sequence.

```
mutating func formIntersection<S>(_ other: S) where Element == S.Element, S : Sequence
```

## Parameters

`other`

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

## Discussion

In the following example, the elements of the `employees` set that are
not also members of the `neighbors` set are removed. In particular, the
names `"Alicia"`, `"Chris"`, and `"Diana"` are removed.

```
var employees: Set = ["Alicia", "Bethany", "Chris", "Diana", "Eric"]
let neighbors = ["Bethany", "Eric", "Forlani", "Greta"]
employees.formIntersection(neighbors)
print(employees)
// 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)