How to check if a UIViewController is of a particular sub-class in objective c?

6 Solutions Collect From Internet About “How to check if a UIViewController is of a particular sub-class in objective c?”

The isKindOfClass: method indicates whether an object is an instance of given class or an instance of a subclass of that class.

if ([instance1 isKindOfClass:[CustomUIViewController class]]) {
    // code
}

If you want to check whether an object is an instance of a given class (but not an instance of a subclass of that class), use isMemberOfClass: instead.

var someVC: UIViewController

if someVC is MyCustomVC {
    //code
}

Swift version:

var someVC: UIViewController

if someVC.isKindOfClass(MyCustomVC) {
    //code
}

Try:

[vc isKindOfClass:[CustomViewController class]];

I just wanted to add in addition to this answer that if you’re wanting to see if a view controller is of a certain type in a switch statement (in Swift) you can do it like this:

var someVC: UIViewController?

switch someVC {
    case is ViewController01: break
    case is ViewController02: break
    case is ViewController03: break
    default: break
}

Swift 3.0
in latest, we have to add a self along with the class name
or it will throw an error “Expected member name or constructor call after type name
the below code u can use for Swift 3 and above

  for viewController in viewControllers {
                            if viewController.isKind(of: OurViewController.self){
                                print("yes it is OurViewController")
                                self.navigationController?.popToViewController(viewController, animated: true)
                            }
                        }