In the code block below, there is a problem understanding 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." }
Console exit
vegetableComment: Is it spicy red pepper
It seems that the following logic is happening.
x = vegetable if (x suffix == 'pepper') run case
Can someone explain this better for me?
swift swift-playground
Arian faurtosh
source share