Skip to content

Instantly share code, notes, and snippets.

@iSapozhnik
Created June 30, 2016 18:53
Show Gist options
  • Save iSapozhnik/ed256c4d1872c7f29bae1f5fda7e9225 to your computer and use it in GitHub Desktop.
Save iSapozhnik/ed256c4d1872c7f29bae1f5fda7e9225 to your computer and use it in GitHub Desktop.
[Swift] UIView loaded from Xib
protocol UIViewLoading {}
extension UIView : UIViewLoading {}
extension UIViewLoading where Self : UIView {
static func loadFromNib() -> Self {
let nibName = "\(self)".characters.split{$0 == "."}.map(String.init).last!
let bundle = NSBundle(forClass: self)
let nib = UINib(nibName: nibName, bundle: bundle)
return nib.instantiateWithOwner(self, options: nil).first as! Self
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment