Created
February 20, 2017 09:41
-
-
Save pbrewczynski/3f7b8396ccc06b32ccc3e1ee99e17672 to your computer and use it in GitHub Desktop.
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 { | |
// 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