Skip to content

Instantly share code, notes, and snippets.

@letatas
Created January 13, 2020 14:36
Show Gist options
  • Save letatas/8acb81b4b50caf1433fdca6eedde6899 to your computer and use it in GitHub Desktop.
Save letatas/8acb81b4b50caf1433fdca6eedde6899 to your computer and use it in GitHub Desktop.
ReusableXibViews - UIView extension to load xib
//
// UIView+Nib.swift
// ReusableXibViews
//
// Created by Matthias Lamoureux on 13/01/2020.
// Copyright © 2020 QSC. All rights reserved.
//
import UIKit
extension UIView {
/// Load the view from a nib file called with the name of the class
///
/// - Note: The first object of the nib file **must** be of the matching class
static func loadFromNib() -> Self {
let bundle = Bundle(for: self)
let nib = UINib(nibName: String(describing: self), bundle: bundle)
return nib.instantiate(withOwner: nil, options: nil).first as! Self
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment