Skip to content

Instantly share code, notes, and snippets.

@deathlezz
Created October 17, 2021 08:58
Show Gist options
  • Save deathlezz/ffb10e8a0308f3119a2c07417e29b364 to your computer and use it in GitHub Desktop.
Save deathlezz/ffb10e8a0308f3119a2c07417e29b364 to your computer and use it in GitHub Desktop.
Simple use of sets in Swift 5.
//
// 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