Hi,
How do I test whether an object is an instance of a particular class in objective c? Let's say I want to see if object a is an instance of class b, or class c, how do I go about doing it? Thanks!
Hi,
How do I test whether an object is an instance of a particular class in objective c? Let's say I want to see if object a is an instance of class b, or class c, how do I go about doing it? Thanks!
you can use
NSString *className = NSStringFromClass([myObject class]);
on a NSObject
To test if object is an instance of class a:
[yourObject isKindOfClass:[a class]]
// Returns a Boolean value that indicates whether the receiver is an instance of
// given class or an instance of any class that inherits from that class.
or
[yourObject isMemberOfClass:[a class]]
// Returns a Boolean value that indicates whether the receiver is an instance of a
// given class.
To get object's class name you can use
const char* className = class_getName([yourObject class]);