Created
October 17, 2021 08:58
-
-
Save deathlezz/ffb10e8a0308f3119a2c07417e29b364 to your computer and use it in GitHub Desktop.
Simple use of sets in Swift 5.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Simple use of sets | |
// | |
// basic set | |
var colors = Set(["yellow", "green", "green", "black", "purple"]) | |
print(colors) // ["purple", "yellow", "black", "green"] | |
colors.remove("green") | |
print(colors) // ["black", "purple", "yellow"] | |
colors.insert("blue") | |
print(colors) // ["blue", "black", "purple", "yellow"] | |
// empty set | |
var empty = Set<Int>() | |
empty.insert(1) | |
empty.insert(2) | |
empty.insert(3) | |
print(empty) // [2, 3, 1] | |
empty.remove(3) | |
print(empty) // [2, 1] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment