Re: Creating a Class Instance By Name
Re: Creating a Class Instance By Name
- Subject: Re: Creating a Class Instance By Name
- From: Andrew Pinski <email@hidden>
- Date: Wed, 8 Dec 2004 00:21:43 -0500
On Dec 8, 2004, at 12:14 AM, Seth Willits wrote:
I need to create a class instance based on its name (as
NSDocumentController does from the Info.plist in every document-based
application) but I can't figure out the exact steps to do so. I'm
doing:
Class class = objc_getClass("MyClassName");
id instance = class_createInstance(class, 0);
Try this instead:
id class = objc_getClass("MyClassName");
id instance = [[class alloc]init];
here the object acts as a class and an object, this is the powerful
part of Objective-C comes in handing.
Otherwise:
you do this:
Class class = (Class)objc_getClass("MyClassName");
id instance = [class_createInstance(class, 0) init];
Both are about the same except the first is more correct as the
class might have its own class alloc message.
Thanks,
Andrew Pinski
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden