Last active
July 14, 2022 22:12
-
-
Save nkukushkin/8972b9c7db89a177384df1ed6ca0da93 to your computer and use it in GitHub Desktop.
Recursive search for the first superview matching certain criteria.
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 firstSuperview<T>(where predicate: (T) -> Bool) -> T? where T: UIView { | |
if let superview = superview as? T, predicate(superview) { | |
return superview | |
} | |
return superview?.firstSuperview(where: predicate) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example: