• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Class name
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Class name


  • Subject: Re: Class name
  • From: Ricky Sharp <email@hidden>
  • Date: Mon, 22 Nov 2004 12:09:50 -0600

On Monday, November 22, 2004, at 11:43AM, <email@hidden> 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)

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Class name
      • From: Ricky Sharp <email@hidden>
References: 
 >Class name (From: email@hidden)

  • Prev by Date: Re: Class name
  • Next by Date: Re: Class name
  • Previous by thread: Re: Class name
  • Next by thread: Re: Class name
  • Index(es):
    • Date
    • Thread