-
-
Save shakemno/a2486ea3516c79c16b2bb905d9b077f6 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) | |
} | |
} | |
// view.firstSuperview(where: { (view: UITableView) in view.isEditing }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment