Citát Michael Gardner <[EMAIL PROTECTED]>:

> Ah, I thought I couldn't use the usual alloc method since I'm obtaining the
> Class dynamically. I didn't even realize you could do something like the
> following:
> 
> [objc_getClass("Foo") alloc]
> 

Simple rule. Do this:

NSString *myClassName; /* Assume this exists and is for example @"Foo" */
Class aClass;

aClass = NSClassFromString(myClassName);
object = [[myClass alloc] init];

... if you do NOT KNOW the class at the time of writing the code.

or do this:

object = [[Foo alloc] init];

... if you DO KNOW the class at the time of writing the code.

Use NSClassFromString() instead of objc_getClass for compatibility reasons,
unless you are writing non-GNUstep/Cocoa - pure ObjectiveC code.

> since I'm used to static methods as they're implemented in C++ and Java, and
> forgot that class methods in Obj-C realy are just instance methods of a
> Class object. Got some unlearning to do, it seems...
> 

Be pre pared for more differences ;-)

Regards,

Stefan Urbanek
--
http://stefan.agentfarms.net

First they ignore you, then they laugh at you, then they fight you, then
you win.
- Mahatma Gandhi


_______________________________________________
Gnustep-dev mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/gnustep-dev

Reply via email to