首页 > 代码库 > swift官方文档中的switch中case let x where x.hasSuffix("pepper")是什么意思?

swift官方文档中的switch中case let x where x.hasSuffix("pepper")是什么意思?

在官方文档中,看到这句。但不明白什么意思。

 

let vegetable = "red pepper"switch vegetable {        case "celery":            let vegetableComment = "Add some raisins and make ants on a log"        case "cocumber", "watercress":            let vegetableComment = "That would make a good tea sandwich."        case let x where x.hasSuffix("pepper"):            let vegetableComment = "Is it a spicy \(x)?"        default:            let vegetableComment = "Everything tastes good in soup.123321"}

经过查资料,才发现这个是后缀的意思:

asPrefix:和hasSuffix:

前缀和后缀。