Getting name of the class from an instance

Viewed 70453

I have the following problem: I get an instance of a class passed and want to know the name of the class of this instance. How to get this?

7 Answers

NSStringFromClass([instance class]) should do the trick.

if all you want to do is test an object to see if it's a type of a certain Class

BOOL test = [self isKindOfClass:[SomeClass class]];

OBJC:

NSStringFromClass([instance class])

SWIFT

From instance:

String(describing: YourType.self)

From type:

String(describing: self)
Related