Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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?
- }
- }
Add Comment
Please, Sign In to add comment