Created
August 30, 2016 20:05
-
-
Save fdocr/0889971ce878b92e2f9963c224312571 to your computer and use it in GitHub Desktop.
Extension for a UIView to find the first superview matching a certain class (or nil)
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 { | |
func findSuperviewWithClass<T>(superViewClass : T.Type) -> UIView? { | |
var xsuperView : UIView! = self.superview! | |
var foundSuperView : UIView! | |
while (xsuperView != nil && foundSuperView == nil) { | |
if xsuperView.self is T { | |
foundSuperView = xsuperView | |
} else { | |
xsuperView = xsuperView.superview | |
} | |
} | |
return foundSuperView | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment