Ser Pounce
Ser Pounce

Reputation: 14571

Given an object, possible to get its class name and convert it to a string?

Suppose I have the object *x of class Illustration. Using x, I'd like to extract its class name into a string so I have @"Illustration". Is it possible to do this?

Upvotes: 0

Views: 1168

Answers (2)

Ahmed Mohammed
Ahmed Mohammed

Reputation: 1154

Use NSStringFromClass.

NSString* className = NSStringFromClass([x class]);

NSString* className = [[x class] description];

Upvotes: 5

Sabir Ali
Sabir Ali

Reputation: 141

You can use NSStringFromClass([x class])

Upvotes: 0

Related Questions