//Create a Se
//Set kosong
var letters = Set()
print("letters is of type Set with \(letters.count) items.")
// Mencetak "letters is of type Set with 0 items.
//Membuat set dengan array literal
var favoriteGenres: Set<String> = ["Rock", "Classical", "Hip hop"]
// favoriteGenres dinisialisasi
var favoriteGenres: Set = ["Rock",]
//Accessing and Modifying a Set
//Count
print("I have \(favoriteGenres.count) favorite music genres.")
// Mencetak "I have 3 favorite
//isEmpty
if favoriteGenres.isEmpty {
print("As far as music goes, I'm not picky.")
} else {
print("I have particular music preferences.")
}
// Mencetak "I have particular music preferences
//insert
favoriteGenres.insert("Jazz")
// Sekarang favoriteGenres mempunyai 4 item
//remove
if let removedGenre = favoriteGenres.remove("Rock") {
print("\(removedGenre)? I'm over it.")
} else {
print("I never much cared for that.")
}
// Mencetak "Rock? I'm over it.
//Contains
if favoriteGenres.contains("Funk") {
print("I get up on the good foot.")
} else {
print("It's too funky in here.")
}
// Mencetak "It's too funky in here.
// For-in
for genre in favoriteGenres {
print("\(genre)")
}
// Classical
// Jazz
// Hip hop
for genre in favoriteGenres.sorted() {
print("\(genre)")
}
// Classical
// Hip hop
// Jazz