我希望能够将数组[String]
中的任何字符串用作Swift case
中的特定switch
语句,如下所示:
var yummy = ["apple", "banana", "orange"]
switch fruit{
case "pineapple":
//...
case "mango":
//...
case yummy: //<-- apple, banana, or orange would satisfy this case
//...
default:break
}
如何转换yummy
以便在case
声明中检查其每个项目是否匹配?