Last active
November 27, 2020 16:35
-
-
Save Czajnikowski/208848422554950b802013ac04260074 to your computer and use it in GitHub Desktop.
Configured instance
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
private func configured<Instance>( | |
_ instance: Instance, | |
configure: (Instance) -> Void | |
) -> Instance where Instance: AnyObject { | |
configure(instance) | |
return instance | |
} | |
infix operator <~ | |
func <~<Instance>( | |
instance: Instance, | |
configure: (Instance) -> Void | |
) -> Instance where Instance: AnyObject { | |
return configured(instance, configure: configure) | |
} |
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
let label1 = UILabel() <~ { | |
$0.text = "Some text" | |
} | |
let label2 = { | |
let label = UILabel() | |
label.text = "Some text" | |
return label | |
}() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment