🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.next.programmer
Article #1473

re: class instances from char string

#1473
From: chris Chris Larson
Date: Wed, 14 Oct 1992 15:37
42 lines
1772 bytes
Thanks to all who responded to my question.  I post an example answer for anyone
interested in this question.

=============================================================================

In comp.sys.next.software article <BvvAv9.2tD@oceania.com> you wrote:
> I would really like to be able to setup a list of character strings that represent  
> classes, and at run time be able to create an instance of the class from the class  
name.
> 
> An example:
> 
> classList[] = {
> "Class1",
> "Class2"};
> 
> then at run time do some type of alloc & init from the class name. ie:
> 
> newClass = [[classList[0] alloc] init]
> 
> Any ideas?

Very simple, it's part of the runtime system:

newClass = [[objc_getClass(classList[0]) alloc] init]

Real-time symbolic mapping! Nothing beats having a compiler and linker available at  
runtime.  8^)

BTW, these kinds of questions will probably get faster answers if posted to  
c.s.n.programmer.

--
Gregory H. Anderson          | "We're very tolerant around here,
Benevolent Dictator-for-Life |  being only amateurs ourselves."
Anderson Financial Systems   | - Tortoise (Godel, Escher, Bach)
greg@afs.com  (Nextmail OK)  | 

-- 
Chris Larson  <==>  chris@oceania.com  <==>  NeXT Mail is cool
Oceania Health Care Systems                      Palo Alto, CA
The Software Ranch                               Park City, UT
Technical Details
Message-ID: <Bw4BDz.38y@oceania.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!oceania!chris

Show Full Headers
Complete Article Headers
Newsgroups: comp.sys.next.programmer
Path: arc1-ca.pugleaf.net!sparky!uunet!oceania!chris
From: chris (Chris Larson)
Subject: re: class instances from char string
Message-ID: <Bw4BDz.38y@oceania.com>
Sender: chris@oceania.com (Chris Larson)
Reply-To: chris@oceania.com
Organization: Oceania Health Care Systems
Distribution: usa
Date: Wed, 14 Oct 1992 15:37:10 GMT
Lines: 42