Is there any way to get class name of parent VC in present (child) UIViewController
? My \'child\' VC (push) has two \'parent\'UIViewController
s, so I w
First add extension in view controller
extension UIView {
var parentViewController: UIViewController? {
var parentResponder: UIResponder? = self
while parentResponder != nil {
parentResponder = parentResponder!.next
if let viewController = parentResponder as? UIViewController {
return viewController
}
}
return nil
}
}
Now Use it Like this
let vc = self.parentViewController
or
if let parentVC = self.parentViewController {
if let parentVC = parentVC as? someViewController {
// parentVC is someViewController
} else if let parentVC = parentVC as? anotherViewController {
// parentVC is anotherViewController
}
}