I have a functionBuilder
@_functionBuilder
struct MyBuilder {
static func buildBlock(_ numbers: Int...) -> Int {
var result = 0
for number in numbers {
result += number * 2
}
return result
}
}
Function
func myFunc(@MyBuilder builder: () -> Int) -> Int {
builder()
}
use
let a = myFunc {
10
20
}
print(a) // print 60 is work!
but
let b = myFunc {
10
}
print(b) // print 10?
Why is b not 20?
I try add other buildBlock
static func buildBlock(number: Int) -> Int {
return number * 2
}
But not working :(
Any idea?