以下のコード ブロックでは、 を理解できません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 "cucumber", "watercress":
let vegetableComment = "That would make a good tea sandwhich"
case let x where x.hasSuffix("pepper"):
let vegetableComment = "Is it a spicy \(x)"
default:
let vegetableComment = "Everything tastes good in soup."
}
コンソール出力
野菜コメント:辛い唐辛子ですか
次のロジックが発生しているようです。
x = vegetable
if (x's suffix == 'pepper')
run case
誰かが私のためにこれをよりよく説明できますか?