Created
September 29, 2022 07:40
-
-
Save yucelokan/0e276a7ac22bf1c77659bf586ae336a8 to your computer and use it in GitHub Desktop.
An extension to initialize custom view.
This file contains 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
// please don't forget to add the custom class for your UIView on the interface builder. | |
public extension UIView { | |
static func initFromNib() -> Self { | |
guard let view = UINib(nibName: String(describing: self), bundle: nil) | |
.instantiate(withOwner: nil, options: nil).first as? Self else { | |
fatalError("Could not init view") | |
} | |
return view | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment