Skip to content

Instantly share code, notes, and snippets.

@Czajnikowski
Last active November 27, 2020 16:35
Show Gist options
  • Save Czajnikowski/208848422554950b802013ac04260074 to your computer and use it in GitHub Desktop.
Save Czajnikowski/208848422554950b802013ac04260074 to your computer and use it in GitHub Desktop.
Configured instance
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)
}
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