Created
September 11, 2015 10:24
-
-
Save maximbilan/0a98b95136c1c8c52550 to your computer and use it in GitHub Desktop.
Swift 2.0 Simple extension for loading UIView with XIB
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 | |
public extension UIView { | |
public class func instantiateFromNib<T: UIView>(viewType: T.Type) -> T { | |
let url = NSURL(string: NSStringFromClass(viewType)) | |
return NSBundle.mainBundle().loadNibNamed(url?.pathExtension, owner: nil, options: nil).first as! T | |
} | |
public class func instantiateFromNib() -> Self { | |
return instantiateFromNib(self) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment