I want to check whether navigation controller's viewcontroller containing ABC Viewcontroller or not if it containing want to pop to previous viewcontroller of ABC else want to popviewcontroller
class Common:UIViewController{
class func returnclassviewcontroller(storybordname:String,classname:String)->UIViewController{
let sb = UIStoryboard.init(name: storybordname, bundle: nil)
var viewcontroller:UIViewController!
viewcontroller = sb.instantiateViewController(withIdentifier: classname)
return viewcontroller
}
}
if let abcclass = Common.returnclassviewcontroller(storybordname: Constant.StoryboardNameLead,
classname: "ABC") as? ABC{
if(self.navigationController?.viewControllers.contains(abcclass)?? false){
if let index = self.navigationController?.viewControllers.indexOf(abcclass){
self.navigationController?.popToViewController(self.navigationController?.viewControllers[index-1] ??
self, animated: true)
}else{
self.navigationController?.popViewController(animated: true)
}
}
}else{
self.navigationController?.popViewController(animated: true)
}
``
I am reaching to else part everytime , Though ABC Class is in naviagtion constorller's subview controller never reach to "self.navigationController?.popToViewController(self.navigationController?.viewControllers[index-1] ??
self, animated: true)"