Skip to content

Instantly share code, notes, and snippets.

@pbrewczynski
Created February 20, 2017 09:41
Show Gist options
  • Save pbrewczynski/cdd8b73d20d0bf0971a32061417b92bf to your computer and use it in GitHub Desktop.
Save pbrewczynski/cdd8b73d20d0bf0971a32061417b92bf to your computer and use it in GitHub Desktop.
protocol UIViewLoading {}
extension UIView : UIViewLoading {}
extension UIViewLoading where Self : UIView {
// note that this method returns an instance of type `Self`, rather than UIView
static func loadFromNib() -> Self {
let nibName = "\(self)".characters.split{$0 == "."}.map(String.init).last!
let nib = UINib(nibName: nibName, bundle: nil)
return nib.instantiate(withOwner: self, options: nil).first as! Self
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment