I'm trying to wrap my head around @_functionBuilder
. There is one case I haven't been able to figure out.
I put together this simple example, when there are two passengers this works great. But when there is only 1 I get this error:
error: FunctionBuilder.playground:21:5: error: cannot convert value of type 'Passanger' to closure result type '[Passanger]'
@_functionBuilder
struct PassangerBuilder {
static func buildBlock(_ passangers: Passanger...) -> [Passanger] {
return passangers
}
}
struct Passanger {
let name: String
}
struct Car {
let passangers: [Passanger]
init(@PassangerBuilder _ builder: () -> [Passanger]) {
self.passangers = builder()
}
}
Car {
Passanger(name: "Tom")
// Passanger(name: "Mary")
}