And*_*obs 3 closures init swift
public struct Style {
    public var test : Int?
    public init(_ build:(Style) -> Void) {
       build(self)
    }
}
var s = Style { value in
    value.test = 1
}
在声明变量时给出错误
Cannot find an initializer for type 'Style' that accepts an argument list of type '((_) -> _)'
有谁知道为什么这不起作用,这对我来说似乎是合法的代码
为了记录,这也无济于事
var s = Style({ value in
    value.test = 1
})
传递给构造函数的闭包修改了给定的参数,因此它必须采用inout参数并使用以下方法调用&self:
public struct Style {
    public var test : Int?
    public init(_ build:(inout Style) -> Void) {
        build(&self)
    }
}
var s = Style { (inout value : Style) in
    value.test = 1
}
println(s.test) // Optional(1)
请注意,使用self(如在build(&self))中需要初始化其所有属性.这可以在这里工作,因为选项被隐式初始化为nil.或者,您可以将属性定义为具有初始值的非可选属性:
public var test : Int = 0