This is similar in syntax to the example that initializes using positional constants, but requires the Then
extension from https://github.com/devxoul/Then (attached below).
let label = UILabel().then {
$0.textAlignment = .Center
$0.textColor = UIColor.blackColor(
$0.text = "Hello, World!"
}
The Then
extension:
import Foundation
public protocol Then {}
extension Then
{
public func then(@noescape block: inout Self -> Void) -> Self {
var copy = self
block(©)
return copy
}
}
extension NSObject: Then {}