Last active
June 20, 2020 12:57
-
-
Save AliSoftware/917e04c09ae15a5caedb 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
func using<T: AnyObject>(object: T, execute: (T) throws -> Void) rethrows -> T { | |
try execute(object) | |
return object | |
} | |
import UIKit | |
// Then in some configureView() function of an UIViewController or whatnot… | |
let label1 = using(UILabel()) { | |
$0.backgroundColor = .blackColor() | |
$0.textColor = .whiteColor() | |
$0.textAlignment = .Center | |
$0.text = "Hello" | |
} | |
let label2 = using(UILabel()) { | |
$0.backgroundColor = .whiteColor() | |
$0.textColor = .blueColor() | |
$0.textAlignment = .Natural | |
$0.text = "World" | |
} | |
let view = using(UIView()) { | |
$0.backgroundColor = .yellowColor() | |
$0.addSubview(label1) | |
$0.addSubview(label2) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment