iPhone how to check the type of an Object?

g.revolution picture g.revolution · Sep 2, 2009 · Viewed 56.4k times · Source

I want to check the type of an Object. How can I do that?

The scenario is I'm getting an object. If that object is of type A then do some operations. If it is of type B then do some operations. Currently the type of the object is C that is parent of A and B.

I have two classes AViewController andBViewController. The object I'm getting in UIViewController. Now how to check whether the object is AViewController or BViewController?

Answer

Pavel Yakimenko picture Pavel Yakimenko · Sep 2, 2009
if([some_object isKindOfClass:[A_Class_Name class]])
{
    // do somthing
}