Created
November 7, 2017 11:34
-
-
Save patricklynch/759059bf3d1b895d8cbce8fca62108fc to your computer and use it in GitHub Desktop.
Subview recursive search
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
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