• 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: RFC: Allocating via a protocol/interface
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

References: 
 >Re: RFC: Allocating via a protocol/interface (From: Michael Gersten <email@hidden>)

  • Prev by Date: Re: UndoManager Action Names
  • Next by Date: Re: NSBezierPath (again) and region subtraction.
  • Previous by thread: Re: RFC: Allocating via a protocol/interface
  • Next by thread: Strange Question
  • Index(es):
    • Date
    • Thread