Skip to content

Instantly share code, notes, and snippets.

@fcaldarelli
Created August 14, 2018 23:29
Show Gist options
  • Save fcaldarelli/bb71765adbeed0a89803c95931879a14 to your computer and use it in GitHub Desktop.
Save fcaldarelli/bb71765adbeed0a89803c95931879a14 to your computer and use it in GitHub Desktop.
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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment