Factory method with block
suggest changeThis snippet is Swift 2: the closure is @noescape, the call uses the external name object, and the color is blackColor().
internal func Init<Type>(value : Type, block: @noescape (object: Type) -> Void) -> Type
{
block(object: value)
return value
}
Usage:
Init(UILabel(frame: CGRect.zero)) {
$0.backgroundColor = UIColor.blackColor()
}
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents