This is my optional and class function solution. You can load more than one XIB with identifier.

extension UIView {   class func loadFromNibNamed(_ nibNamed: String, bundle : Bundle? = nil) -> UIView? {     return UINib(nibName: nibNamed, bundle: bundle).instantiate(withOwner: nil, options: nil).first as? UIView   }


let myCustomView = UIView.loadFromNibNamed(identifier) as! CustomView

Written by

Health Research Program’s iOS Developer, currently lives in Washington, D.C http://www.about.me/durul

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store