Skip to content

Instantly share code, notes, and snippets.

@weekwood
Last active May 5, 2017 09:38
Show Gist options
  • Save weekwood/c23645c625ffe7163068ab26d4a5f18b to your computer and use it in GitHub Desktop.
Save weekwood/c23645c625ffe7163068ab26d4a5f18b to your computer and use it in GitHub Desktop.
extension UIView {
@discardableResult
func fromNib<T : UIView>() -> T? {
guard let view = Bundle.main.loadNibNamed(String(describing: type(of: self)), owner: self, options: nil)?[0] as? T else {
return nil
}
return view
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment