Looking for swift Answers? Try Ask4KnowledgeBase
Looking for swift Keywords? Try Ask4Keywords

Swift Language Modifying values in a set


Example

var favoriteColors: Set = ["Red", "Blue", "Green"]
//favoriteColors = {"Blue", "Green", "Red"}  

You can use the insert(_:) method to add a new item into a set.

favoriteColors.insert("Orange")
//favoriteColors = {"Red", "Green", "Orange", "Blue"}

You can use the remove(_:) method to remove an item from a set. It returns optional containing value that was removed or nil if value was not in the set.

let removedColor = favoriteColors.remove("Red")
//favoriteColors = {"Green", "Orange", "Blue"}
// removedColor = Optional("Red")

let anotherRemovedColor = favoriteColors.remove("Black")
// anotherRemovedColor = nil