Skip to content

Instantly share code, notes, and snippets.

@maximbilan
Created September 11, 2015 10:24
Show Gist options
  • Save maximbilan/0a98b95136c1c8c52550 to your computer and use it in GitHub Desktop.
Save maximbilan/0a98b95136c1c8c52550 to your computer and use it in GitHub Desktop.
Swift 2.0 Simple extension for loading UIView with XIB
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