Created
August 14, 2018 23:29
-
-
Save fcaldarelli/bb71765adbeed0a89803c95931879a14 to your computer and use it in GitHub Desktop.
UIView from nib
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
extension UIView { | |
class func fromNib<T: UIView>() -> T { | |
return Bundle.main.loadNibNamed(String(describing: T.self), owner: nil, options: nil)![0] as! T | |
} | |
} | |
//Then call it like this: | |
let myCustomView: CustomView = UIView.fromNib() | |
//..or even: | |
let myCustomView: CustomView = .fromNib() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment