Last active
June 18, 2018 11:12
-
-
Save a2/7409f8b76dda76be6dc63fe7685b3fbf to your computer and use it in GitHub Desktop.
This file contains 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