Skip to content

Instantly share code, notes, and snippets.

@patricklynch
Created November 7, 2017 11:34
Show Gist options
  • Save patricklynch/759059bf3d1b895d8cbce8fca62108fc to your computer and use it in GitHub Desktop.
Save patricklynch/759059bf3d1b895d8cbce8fca62108fc to your computer and use it in GitHub Desktop.
Subview recursive search
extension UIView {
func findSubview(where matches: (UIView) -> Bool) -> UIView? {
for subview in subviews {
if matches(subview) {
return subview
} else if let match = subview.findSubview(where: matches) {
return match
}
}
return nil
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment