检查集合是否包含值
var favoriteColors: Set = ["Red", "Blue", "Green"]
//favoriteColors = {"Blue", "Green", "Red"}
你可以使用 contains(_:)
方法检查集合是否包含值。如果集合包含该值,它将返回 true。
if favoriteColors.contains("Blue") {
print("Who doesn't like blue!")
}
// Prints "Who doesn't like blue!"