Skip to content

Instantly share code, notes, and snippets.

@kyleve kyleve/Init.swift
Last active Feb 3, 2018

Embed
What would you like to do?
// Make initialization + configuration of mutable classes (such as views) easier.
@warn_unused_result
public func Init<Type>(value : Type, @noescape block: (object: Type) throws -> Void) rethrows -> Type
{
try block(object: value)
return value
}
func example()
{
let label = Init(UILabel()) {
$0.font = UIFont.boldSystemFontOfSize(13.0)
$0.text = "Hello, World"
$0.textAlignment = .Center
}
}
@jasonsilberman

This comment has been minimized.

Copy link

jasonsilberman commented Jan 2, 2016

👍

@matthewcheok

This comment has been minimized.

Copy link

matthewcheok commented Jan 2, 2016

@noescape?

@kyleve

This comment has been minimized.

Copy link
Owner Author

kyleve commented Jan 2, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.