Initialize with then

suggest change

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(&copy)
        return copy
    }
}

extension NSObject: Then {}

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents