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

# subtracting(_:)

Returns a new set containing the elements of this set that do not occur
in the given sequence.

```
func subtracting<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 `nonNeighbors` set is made up of the
elements of the `employees` set that are not elements of `neighbors`:

```
let employees: Set = ["Alicia", "Bethany", "Chris", "Diana", "Eric"]
let neighbors = ["Bethany", "Eric", "Forlani", "Greta"]
let nonNeighbors = employees.subtracting(neighbors)
print(nonNeighbors)
// Prints "["Chris", "Diana", "Alicia"]"
```

---

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)