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

# symmetricDifference(_:)

Returns a new set with the elements that are either in this set or in the
given set, but not in both.

```
func symmetricDifference(_ other: Self) -> Self
```

## Parameters

`other`

A set of the same type as the current set.

## Return Value

A new set.

## Discussion

In the following example, the `eitherNeighborsOrEmployees` set is made up
of the elements of the `employees` and `neighbors` sets that are not in
both `employees` *and* `neighbors`. In particular, the names `"Bethany"`
and `"Eric"` do not appear in `eitherNeighborsOrEmployees`.

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