• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Creating a Class Instance By Name
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >Creating a Class Instance By Name (From: Seth Willits <email@hidden>)

  • Prev by Date: Creating a Class Instance By Name
  • Next by Date: Re: Creating a Class Instance By Name
  • Previous by thread: Creating a Class Instance By Name
  • Next by thread: Re: Creating a Class Instance By Name
  • Index(es):
    • Date
    • Thread