在官方文档中,看到这句。但不明白什么意思。
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:
前缀和后缀。
swift官方文档中的switch中case let x where x.hasSuffix("pepper")是什么意思?
时间: 2024-10-14 02:51:42