From ba8e361cbffe05268bb2141152be958f9ad5e374 Mon Sep 17 00:00:00 2001 From: Carlos Andres Chaguendo Sanchez Date: Thu, 28 Jun 2018 17:34:24 -0500 Subject: [PATCH] simplifying initializers let label = UILabel { $0.textAlignment = .center $0.textColor = .black $0.text = "Hello, World!" } --- Sources/Then/Then.swift | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Sources/Then/Then.swift b/Sources/Then/Then.swift index 2be8422..39663a6 100644 --- a/Sources/Then/Then.swift +++ b/Sources/Then/Then.swift @@ -71,6 +71,23 @@ extension Then where Self: AnyObject { } +extension Then where Self: NSObject { + + + /// Makes it available to set properties with closures just after initializing. + /// + /// let label = UILabel { + /// $0.textAlignment = .Center + /// $0.textColor = UIColor.blackColor() + /// $0.text = "Hello, World!" + /// } + init(block: (Self) -> Void) { + self.init() + block(self) + } + +} + extension NSObject: Then {} extension CGPoint: Then {}