Tutorial by Examples

Avoid code repetition in constructors by setting a tuple of variables with a one liner: class Contact: UIView { private var message: UILabel private var phone: UITextView required init?(coder aDecoder: NSCoder) { (message, phone) = self.dynamicType.setUp() su...
let mySwitch: UISwitch = { view.addSubview($0) $0.addTarget(self, action: "action", forControlEvents: .TouchUpInside) return $0 }(UISwitch())
@IBOutlet weak var title: UILabel! { didSet { label.textColor = UIColor.redColor() label.font = UIFont.systemFontOfSize(20) label.backgroundColor = UIColor.blueColor() } } It's also possible to both set a value and initialize it: private var loginButton = UIButton() { ...
Move every outlet to an NSObject. Then drag an Object from the library to the controller scene of the storyboard and hook the elements there. class ContactFormStyle: NSObject { @IBOutlet private weak var message: UILabel! { didSet { message.font = UIFont.systemFontOfSize(12) ...
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 = "Hell...
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() }

Page 1 of 1