Created
October 2, 2022 14:49
-
-
Save AhmedMenaim/365fafc56bbd63dd93cb751619166c6b to your computer and use it in GitHub Desktop.
Menaim Academy - Swift Course - Collection Types - Sets
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
import Foundation | |
// MARK: - What is the Set !? | |
// Unarranged list , perform operations, | |
// MARK: - Create Set | |
var letters = Set<Character>() | |
var names: Set<String> = ["ahmed", "mohamed", "Fawzy", "Menaim"] | |
print(names) | |
var animals: Set = ["Dog", "Cat"] | |
// MARK: - Accessing and Modifying a Set | |
animals.insert("Horse") | |
print(animals) | |
print(animals.count) | |
if animals.isEmpty { // if animals.count == 0 | |
print("isEmpty") | |
} | |
else { | |
print("Full") | |
} | |
names.remove("Fawzy") | |
print(names) | |
// MARK: - Set Operations | |
let oddDigits: Set = [1, 3, 5, 7, 9] | |
let evenDigits: Set = [0, 2, 4, 6, 8] | |
let allNumbers = evenDigits.union(oddDigits) | |
allNumbers.sorted() | |
evenDigits.intersection(oddDigits) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment