Re: creating instance using Class variable
Re: creating instance using Class variable
- Subject: Re: creating instance using Class variable
- From: Ken Thomases <email@hidden>
- Date: Wed, 20 Aug 2008 19:28:50 -0500
On Aug 20, 2008, at 7:02 PM, Eliza Block wrote:
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.
Doesn't work how?
I believe that's exactly how it's supposed to work.
Cheers,
Ken
_______________________________________________
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