Re: [Pyobjc-dev] Access to 'hidden' class-methods
Brought to you by:
ronaldoussoren
From: Ronald O. <ous...@ci...> - 2003-01-12 21:54:48
|
On Sunday, Jan 12, 2003, at 22:36 Europe/Amsterdam, Jack Jansen wrote: > > On zondag, jan 12, 2003, at 20:36 Europe/Amsterdam, Ronald Oussoren > wrote: >> >> Right. A class is an instance of its meta-class and class-methods are >> in fact normal methods of the meta-class [...] > > Are you sure this is the case? Then how can I access "self" in a class > method (which would be the class)? Or is the only reason I can't get > at self in a class method is that the ObjC syntactic sugar doesn't > allow it? You can, but inside a class method 'self' refers to the class instead of instances of the class. $ cat t.m #include <Foundation/Foundation.h> @interface TestClass :NSObject { } +classMethod; @end @implementation TestClass +classMethod { printf("%p: Self of class method\n", self); printf("%p: Class TestClass\n", [TestClass class]); return 0; } @end int main(void) { [TestClass classMethod]; } $ cc -o t t.m -framework Foundation $ ./t 0x400c: Self of class method 0x400c: Class TestClass > > Hmm, another wild idea: would this mean that by declaring a category > on the metaclass you could influence creation of all ObjC objects? You probably could, but: the metaclass has the same name as the normal class which makes it hard to define a category on it. But is guess defining a category containing class-mehods on a normal class would do what you want. Ronald |