// *** in version 5.8: ***
//any variables are allowed
//inside a result builder
@resultBuilder
struct TextBuilder {
static func buildBlock(
_ parts: String...) -> String {
parts.joined(separator: " ")
}
}
func makeText(
@TextBuilder _ build: () -> String)
-> String {
build()
}
let text = makeText {
lazy var hello = "Hello,"
let name = "Alina"
hello
name
}
print("text is \"\(text)\"")
//text is "Hello, Alina"
| Lift all limitations on variables in result builders (SE-0373). For example, in Swift 5.8 we can use lazy variables directly inside result builders. |