Skip to content

Instantly share code, notes, and snippets.

@jegnux
Last active October 6, 2021 08:33
Show Gist options
  • Save jegnux/44a00423ca6f367d25f08df37db59759 to your computer and use it in GitHub Desktop.
Save jegnux/44a00423ca6f367d25f08df37db59759 to your computer and use it in GitHub Desktop.
prefix operator ..
infix operator ..: MultiplicationPrecedence
/*
Custom operator that lets you configure an instance inline
```swift
let label = UILabel()..{
$0.numberOfLines = 0
$0.textColor = .systemRed
}
```
*/
@discardableResult
public func .. <T>(object: T, configuration: (inout T) -> Void) -> T {
var object = object
configuration(&object)
return object
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment