Last active
January 30, 2020 18:46
-
-
Save grdsdev/d616601e5ae0bbd9815c82178f92a01b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
protocol ViewConfigurable {} | |
extension ViewConfigurable where Self: UIView { | |
func configure(_ block: (Self) -> Void) -> Self { | |
block(self) | |
return self | |
} | |
} | |
extension UIView: ViewConfigurable {} | |
final View: UIView { | |
// Assim é mais verboso | |
private let label: UILabel = { | |
let label = UILabel() | |
label.text = "Hello World" | |
label.textColor = .red | |
return label | |
}() | |
// Com o configure, fica menos verboso. | |
private let label = UILabel().configure { | |
$0.text = "Hello World" | |
$0.textColor = .red | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment