Last active
          January 18, 2016 20:47 
        
      - 
      
- 
        Save 646b/53a49147a35d4224bb7c to your computer and use it in GitHub Desktop. 
    Useful UIView extensions
  
        
  
    
      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 { | |
| /** | |
| Searches for superview with specified type in view hierarchy | |
| let cell = button.superviewOfType(UITableViewCell.self) | |
| - Parameter type: Type of superview | |
| - Returns: A superview of specified type | |
| */ | |
| func superviewOfType<T>(type: T.Type) -> T? { | |
| var currentView = self | |
| while let superview = currentView.superview { | |
| if superview is T { | |
| return superview as? T | |
| } | |
| currentView = superview | |
| } | |
| return nil | |
| } | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment