Created
February 8, 2016 16:58
-
-
Save pcperini/5a8ea37e8cbbe904a031 to your computer and use it in GitHub Desktop.
This file contains 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
public extension CollectionType { | |
// MARK: Flatteners | |
public func flatten(path: (Self.Generator.Element) -> [Self.Generator.Element]) -> [Self.Generator.Element] { | |
guard !self.isEmpty else { return [] } | |
return self + self.flatMap { path($0).flatten(path) } | |
} | |
} | |
public extension UIView { | |
// MARK: Properties | |
public var flatSubviews: [UIView] { | |
return self.subviews.flatten { $0.subviews } | |
} | |
public var flatConstraints: [NSLayoutConstraint] { | |
return (self.flatSubviews + [self]).flatMap { $0.constraints } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment