Checking whether a set contains a value

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

You can use the contains(_:) method to check whether a set contains a value. It will return true if the set contains that value.

if favoriteColors.contains("Blue") {
    print("Who doesn't like blue!")
}
// Prints "Who doesn't like blue!"

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents