Skip to content

Instantly share code, notes, and snippets.

Created December 12, 2017 10:05
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save StevenMasini/b23b6099222aad28ddfe6dff52e2bae8 to your computer and use it in GitHub Desktop.
extension UIView {
/// Load a view from a nib file and return it.
/// The Class and the Nib file must have the same name.
/// The nib file should contain only one view.
/// - Returns: The first view found in the nib file.
static func loadInstanceFromNib<T: UIView>() -> T? {
return Bundle.main.loadNibNamed(String(describing: classForCoder()), owner: self, options: nil)?[0] as? T
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment