Re: RFC: Allocating via a protocol/interface
Re: RFC: Allocating via a protocol/interface
- Subject: Re: RFC: Allocating via a protocol/interface
- From: "John C. Randolph" <email@hidden>
- Date: Tue, 2 Jul 2002 13:18:19 -0700
On Monday, July 1, 2002, at 10:32 PM, Michael Gersten wrote:
The goal is to be able to allocate a class that isn't known at
compile
time, based on the output of a function.
A class is actually a struct. You could malloc one and use
objc_addClass() to add it to the runtime. There may be an
easier way to
do this.
Ok, misunderstanding. I don't want to create a new class structure.
I want to create an instance of a class.
In that case, you can do something like:
NSString *className;
className = (get it from somewhere at run time..)
NSClass *classToInstantiate = NSClassFromString(className);
id instance = [[classToInstantiate alloc] init];
-jcr
John C. Randolph <email@hidden> (408) 974-8819
Sr. Cocoa Software Engineer,
Apple Worldwide Developer Relations
http://developer.apple.com/cocoa/index.html
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.