.symmetricDifference()
Published Jan 28, 2023
Contribute to Docs
The .symmetricDifference()
method returns a new set with the elements that are either in the set or in the given sequence, but not in both. In other words, it returns a new set with all the elements from two sets that do not overlap.
Syntax
setName.symmetricDifference(otherSetName)
The otherSetName
parameter is a finite sequence of elements.
Example
The following example shows the elements that aren’t common to each set:
let food: Set = ["Apple", "Banana", "Orange", "Peach"]let colors = ["Green", "Blue", "Orange", "Peach"]let eitherFoodOrColor = food.symmetricDifference(colors)
This will display the following:
["Banana", "Green", "Apple", "Blue"]
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn Swift on Codecademy
- Skill path
Build iOS Apps with SwiftUI
Learn how to build iOS applications with Swift and SwiftUI and publish them to Apples' App Store.Includes 7 CoursesWith CertificateBeginner Friendly13 hours - Free course
Learn Swift
A powerful programming language developed by Apple for iOS, macOS, and more.Beginner Friendly12 hours