UIView from nib
extension UIView {
class func fromNib<T: UIView>() -> T {
return Bundle.main.loadNibNamed(String(describing: T.self), owner: nil, options: nil)![0] as! T
}
}
//Then call it like this:
let myCustomView: CustomView = UIView.fromNib()
//..or even:
let myCustomView: CustomView = .fromNib()