Skip to content

Instantly share code, notes, and snippets.

@MojtabaHs
Created November 7, 2020 10:17
Show Gist options
  • Save MojtabaHs/71dee67d75a0bbe11a763e7fc67c8cd6 to your computer and use it in GitHub Desktop.
Save MojtabaHs/71dee67d75a0bbe11a763e7fc67c8cd6 to your computer and use it in GitHub Desktop.
A simple operator to modify the object right at the initialization part.
infix operator ..
@inline(__always)
func ..<T: EmptyInitializable>(lhs: T, rhs: (T)->()) -> T {
rhs(lhs)
return lhs
}
/* Example:
let myLabel = UILabel() .. {
$0.textColor = .red
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment