In the code block below, I am having trouble understanding let x where x.hasSuffix(\"pepper\")
.
let vegetable = \"red pepper\"
switch vegetable {
vegetable
is an implicit String
. It's the same as you would write:
var vegetable: String = "red pepper"
hasSuffix
is declared as func hasSuffix(suffix: String) -> Bool
an therefore returns a Bool
. The where
keyword specifies additional requirements, and can only be used in switch
statements.
Because all of this is suffused, the vegetable
variable is assigned to x (let x
).
You can read more about the where
and switch
here.