Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Filter objects into Optionals
extension Filter {
/// Allows filtering of non sequence types.
///
/// let label = UILabel().then {
/// $0.textAlignment = .Center
/// $0.textColor = UIColor.blackColor()
/// $0.text = "Hello, World!"
/// }
public func filter(@noescape condition: Self -> Bool) -> Self? {
return condition(self) ? self : nil
}
}
extension NSObject: Filter {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment