Created
March 2, 2020 22:36
-
-
Save dagronf/6608307464ba5fb624ff9491b87db0e1 to your computer and use it in GitHub Desktop.
SWIFT: Stream generic functions for NSView and NSCell to allow quick initialisation of properties
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
/// Stream generic functions for NSView and NSCell to allow quick initialisation of properties | |
/// Useful for when your (eg) button variable has a long name or is optional. | |
func <<<T> (left: T, configureBlock: (T) -> Void) -> T where T: NSView { | |
configureBlock(left) | |
return left | |
} | |
func <<<T> (left: T, configureBlock: (T) -> Void) -> T where T: NSCell { | |
configureBlock(left) | |
return left | |
} | |
/// Usage: | |
/// self.performTaskButton = NSButton() << { | |
/// $0.setButtonType(.toggle) | |
/// $0.title = "Button!" | |
/// $0.alternativeTitle = "button pressed" | |
/// $0.setContentHuggingPriority(.required, for: .horizontal) | |
/// $0.setContentHuggingPriority(.required, for: .vertical) | |
/// $0.setContentCompressionResistancePriority(.required, for: .horizontal) | |
/// $0.setContentCompressionResistancePriority(.required, for: .vertical) | |
/// } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment