Skip to content

Instantly share code, notes, and snippets.

@ejmartin504
Created March 13, 2017 16:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ejmartin504/c43c8a5cbbf83fa1952ae86ff3c394d7 to your computer and use it in GitHub Desktop.
Save ejmartin504/c43c8a5cbbf83fa1952ae86ff3c394d7 to your computer and use it in GitHub Desktop.
Load view from a nib file
import UIKit
public extension UIView {
public class func instantiateFromNib<T: UIView>(viewType: T.Type) -> T {
return Bundle.main.loadNibNamed(String(describing: viewType), owner: nil, options: nil)!.first as! T
}
public class func instantiateFromNib() -> Self {
return instantiateFromNib(viewType: self)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment