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

# formSymmetricDifference(_:)

Replace this set with the elements contained in this set or the given
set, but not both.

```
mutating func formSymmetricDifference<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
also members of `neighbors` are removed from `employees`, while the
elements of `neighbors` that are not members of `employees` are added to
`employees`. In particular, the names `"Bethany"` and `"Eric"` are
removed from `employees` while the name `"Forlani"` is added.

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