• 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: Basic runtime function usage - objc_getClass
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Basic runtime function usage - objc_getClass


  • Subject: Re: Basic runtime function usage - objc_getClass
  • From: Francis Derive <email@hidden>
  • Date: Wed, 23 Nov 2005 21:37:58 +0100


On Nov 23, 2005, at 8:42 PM, Francis Derive wrote:


On Nov 23, 2005, at 6:23 PM, Sherm Pendley wrote:

"id" is a typedef for "objc_object*", but in fact it can be either that or "objc_class*", [•••].
objc_getClass() returns a Class (not a Class*), but it's declared as id so that you can easily send messages to it.
(Class, btw, is a typedef for objc_class*)


[...]
For an instance, isa points to a class definition. But for a Class (i.e. for an objc_class struct), isa points to the metaclass, another objc_class.


(gdb) print myPointerToClass->isa->name
There is no member named name.
-- what ? why ? No way to understand !

I'm not certain whether a metaclass has a meaningful name.
I can't think of any reason why it might need one; it's not really useful on its own, only as a part of the class with which it's registered.
If what you want is the name of the class, just declare myPointerToClass as the correct type, and look at its name member directly, for instance:


	if (myPointerToClass) {
		NSLog(@"%s is registered", myPointerToClass->name);
	}

sherm--

Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org


Sherm,

You did it, thanks a lot. I had been a so long time confused : I did want to reach any field like the name of the class, but nothing much about the metaclass.
This is fine - wasn't it confusing - I keep your explanation with me as a solid reference in my future reading the doc.


Cheers,

Francis.

Oh ma ! Horrible ! it doesn't compile !


Class myPointerToClass = (Class) objc_getClass("MYobject");
if (myPointerToClass) {
NSLog( @"%s", myPointerToClass->name);//KVC.m:32: error: dereferencing pointer to incomplete type


	} else {
			NSLog(@"laClasse is NOT registered");
	}

Will it be ?

Francis.

_______________________________________________
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: Basic runtime function usage - objc_getClass
      • From: Sherm Pendley <email@hidden>
References: 
 >Basic runtime function usage - objc_getClass (From: Francis Derive <email@hidden>)
 >Re: Basic runtime function usage - objc_getClass (From: Sherm Pendley <email@hidden>)
 >Re: Basic runtime function usage - objc_getClass (From: Francis Derive <email@hidden>)

  • Prev by Date: Deprecated methods in NSDocument
  • Next by Date: Re: Deprecated methods in NSDocument
  • Previous by thread: Re: Basic runtime function usage - objc_getClass
  • Next by thread: Re: Basic runtime function usage - objc_getClass
  • Index(es):
    • Date
    • Thread