discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: dynamically instantiating a class


From: Marko Mikulicic
Subject: Re: dynamically instantiating a class
Date: Fri, 31 Aug 2001 21:26:01 -0400
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.3) Gecko/20010801

Hi,

Aurelien wrote:
I'm trying to dynamically instantiate a class like so:

Class * clazz;
!!!!

id <PeerGroup> p;

clazz = NSClassFromString ( @"Platform" );
p = (id <PeerGroup>) NSAllocateObject( *clazz, 0, NULL);
!!!!!!

if ( [p conformsTo:@protocol(PeerGroup)] )
  NSLog ( @"Yes, this is indeed a PeerGroup" );
else
  NSLog ( @"No, this isn't a PeerGroup" );

NSClassFromString returns a "Class" not "Class*"
You could also write in a more OO way:

[[NSClassFromString(@"Platform") alloc] init];

I use this quite a lot and it works for me

Marko




reply via email to

[Prev in Thread] Current Thread [Next in Thread]