Skip to content

Instantly share code, notes, and snippets.

@maximbilan
Last active November 10, 2021 12:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maximbilan/e87e84b3968260a31184 to your computer and use it in GitHub Desktop.
Save maximbilan/e87e84b3968260a31184 to your computer and use it in GitHub Desktop.
Swift 1.2 Simple extension for loading UIView with XIB
import UIKit
public extension UIView {
public class func instantiateFromNib<T: UIView>(viewType: T.Type) -> T {
return NSBundle.mainBundle().loadNibNamed(NSStringFromClass(viewType).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