creating instance using Class variable
creating instance using Class variable
- Subject: creating instance using Class variable
- From: Eliza Block <email@hidden>
- Date: Wed, 20 Aug 2008 20:02:44 -0400
Hello,
Does anyone know how to use a variable of type Class to create an
instance of an object?
I'm writing a method that needs to create an instance of one of two
classes, to be determined at run-time. I want to pass in a Class
variable, and have the method use it to create the instance. I know
this must be possible, because NSMatrix does it. You can setCellClass:
for NSMatrix, and then the cells it creates will be instances of the
class you set. But I can't seem to find documentation about how to
actually create the instance.
In short, I want to do something like this:
Class stringClass = [NSString class];
id myNewString = [[stringClass alloc] init];
But that doesn't work.
Any help would be much appreciated!
Thanks,
Eliza
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden