I had take one ViewController with separate nib file. and my initial root viewcontroller is set in the storyBoard. Now the problem is that when I push to this controller the Vi
var viewController = OfferDetailViewController(nibName: "OfferDetailViewController", bundle: nil)
solution with type casting:
extension UIViewController {
static func initFromNib() -> Self {
func instanceFromNib<T: UIViewController>() -> T {
return T(nibName: String(describing: self), bundle: nil)
}
return instanceFromNib()
}
}
enjoyment:
let testVC = TestVC.initFromNib()
testVC.someCustomParam = "someValue"
Here is a nice generic approach...
extension UIViewController {
class func loadFromNib<T: UIViewController>() -> T {
return T(nibName: String(describing: self), bundle: nil)
}
}
let vc : OfferDetailViewController = OfferDetailViewController.loadFromNib()