Skip navigation.
 
mlRe: Class name
FROM : Ricky Sharp
DATE : Mon Nov 22 19:09:50 2004

On Monday, November 22, 2004, at 11:43AM, <<email_removed>> wrote:

>How can i get a name as a NSString of a Class Object?
>
>ex:
>
>Class    _someClass = (Class )NSButton;
>NSString*    _className = [ _someClass ???? ];


I'm reading this as you have a Class, and then need to get it's name.  If that's correct, I believe Class is just a pointer to the objc_class structure.  One of the fields of that struct is a const char* name.

Warning: I've never done any coding with the Obj-C structures directly, so no clue if this will even compile:

- (NSString*)stringForClass:(Class)aClass
{
    objc_class* classStructure = (objc_class*) aClass;

    return [[NSString alloc] initWithCString:[classStructure->name] autorelease];
}

Or, do you have an instance of the class you want a name for?  If so, just call the className method (from NSObject)

--
Rick Sharp
Instant Interactive(tm)

Related mailsAuthorDate
mlClass name alex Nov 22, 18:42
mlRe: Class name Scott Stevenson Nov 22, 19:02
mlRe: Class name Tod Cunningham Nov 22, 19:09
mlRe: Class name Ricky Sharp Nov 22, 19:09
mlRe: Class name Ricky Sharp Nov 22, 19:13
mlRe: Class name Daniel DeCovnick Nov 22, 19:13
mlRe: Class name John C. Randolph Nov 22, 20:13
mlRe: Class name Sherm Pendley Nov 22, 20:30
mlRe: Class name Shawn Erickson Nov 22, 20:43