Created
June 30, 2016 18:53
-
-
Save iSapozhnik/ed256c4d1872c7f29bae1f5fda7e9225 to your computer and use it in GitHub Desktop.
[Swift] UIView loaded from Xib
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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