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
?
Open the Photos app on your iPhone and select a picture with a clearly defined subject, such as a flower or animal. Check the info ("i") icon at the bottom of the screen. If it has a little star over it, tap it – this indicates there's a Visual Lookup you can examine.
Use the typeof operator to get the type of an object or variable in JavaScript. The typeof operator also returns the object type created with the "new" keyword. As you can see in the above example, the typeof operator returns different types for a literal string and a string object.
“Use the type check operator (is) to check whether an instance is of a certain subclass type. The type check operator returns true if the instance is of that subclass type and false if it is not.” Excerpt From: Apple Inc. “The Swift Programming Language.” iBooks.
if([some_object isKindOfClass:[A_Class_Name class]]) { // do somthing }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With