Last active
February 3, 2018 23:01
-
-
Save kyleve/90c889e584b9af6256ae to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 | |
} | |
} |
@noescape
?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
👍