-
-
Save briscula/c6caa0466c4ef9504c636b720d6a2cc5 to your computer and use it in GitHub Desktop.
Traverse View Hierarchy Upwards
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 findFirstSuperview<T>(ofClass viewClass: T.Type, where predicate: (T) -> Bool) -> T? where T: UIView { | |
| var view: UIView? = self | |
| while view != nil { | |
| if let typedView = view as? T, predicate(typedView) { | |
| break | |
| } | |
| view = view?.superview | |
| } | |
| return view as? T | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment