I've been looking at The Swift Programming Language guide provided by apple. Following sample is from the book:
class HTMLElement {
let name :String;
let text: String?;
@lazy var asHTML : () -> String = {
if let text = self.text {
return "<\(self.name)>\(self.text)</\(self.name)>";
} else {
return "<\(self.name) />"
}
}
}
I incorrectly wrote the closure as follow:
@lazy var asHTML : () -> String = {
if (let text = self.text) {
return "<\(self.name)>\(self.text)</\(self.name)>";
} else {
return "<\(self.name) />"
}
}
Notice the parentheses around let text = self.text
and compiler complain about:
Pattern variable binding cannot appear in an expression
Just wondering what does Pattern Variable Binding
mean, and why it cannot appear in an expression?