Re: Is it possible to dynamically create a class?
Re: Is it possible to dynamically create a class?
- Subject: Re: Is it possible to dynamically create a class?
- From: Scott Thompson <email@hidden>
- Date: Fri, 17 Aug 2007 17:14:56 -0500
On Aug 17, 2007, at 5:00 PM, Bob Ueland wrote:
Is it possible to dynamically create a class?
Suppose for instance that I have an object called SimpleClassCreator
that has a method called
createClass which accepts parameters giving the name of the class
and the name and type of instance variables. The createclass would
then dynamically (during runtime) create a class-object with the
given name and the given instance variables, and would create one
setter method and one getter method for each given instance
variable. Is that possible?
The short answer is "Yes", it is possible to do that.
Tools like PyObjC and RubyCocoa use this ability to create NSObject
proxies for Ruby/Python classes and vice-versa.
The longer answer involves the fact that this has traditionally been
somewhat tricky and error-prone through nominally undocumented APIs
which Apple does not recommend relying on.
The high profile given to technologies like the Ruby and Python
integration, or the Scripting Bridge for AppleScript in Leopard
(mentioned in http://developer.apple.com/leopard/overview/
apptech.html) would tend to lead me to two conclusions:
1. Creating classes on the fly may be easier in Leopard than it is in
Tiger
2. Creating classes on the fly may be incompatible so that if you
figure it out for Tiger you're likely to have to redo things in Leopard.
Still, if you want details, rubycocoa and PyObjC are public source
tools and have cutting edge releases that might be of interest.
Scott
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden