-
-
Save ardarda/464dc8023f8d6b755b676d5b7331bec0 to your computer and use it in GitHub Desktop.
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
import UIKit | |
extension UIView { | |
var superviews: UnfoldFirstSequence<UIView> { | |
return sequence(first: self) { view in view.superview } | |
} | |
func enclosingView(where predicate: (UIView) -> Bool) -> UIView? { | |
return superviews.first(where: predicate) | |
} | |
func enclosingView<T>(type: T.Type) -> T? where T: UIView { | |
return superviews.first(where: { $0 is T }) as! T? | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment