Skip to content

Instantly share code, notes, and snippets.

@yucelokan
Created September 29, 2022 07:40
Show Gist options
  • Save yucelokan/0e276a7ac22bf1c77659bf586ae336a8 to your computer and use it in GitHub Desktop.
Save yucelokan/0e276a7ac22bf1c77659bf586ae336a8 to your computer and use it in GitHub Desktop.
An extension to initialize custom view.
// 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