• 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: Subclassing From Code?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Subclassing From Code?


  • Subject: Re: Subclassing From Code?
  • From: Matthew Cox <email@hidden>
  • Date: Mon, 17 Nov 2003 00:09:23 -0500

On Sunday, November 16, 2003, at 08:51 PM, David McGavern wrote:

How can I dynamically make a class a subclass of another class, from code? For example, if I have an LWSearchField (my own class) that I want to make into a NSSearchField (if 10.3 is detected). Any help is greatly appreciated :-).

You are absolutely nuts, good job, I salute you. This is probably the most dangerous thing I can imagine, but what the heck, its creative. I'm sure apple didn't mean for people to play with this stuff, so expect that it might not work as expected.

To do this, you'll need to mess with the ObjC runtime. Have a look at this:

http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC/ 9objc_runtime_reference/chapter_5_section_1.html#//apple_ref/doc/uid/ 20001426

You'll need to grab the objc_class record associated with your class, and change its super_class field. I'm not sure how to get a hold of the class definitions. Maybe someone else will fill us in. It must be a private member of the class object, I guess.

Have fun, and let me know what happens. I'm suspecting your program either gets terminated, or it causes your mac to explode. You hereby relieve me of all liability, civil or otherwise.
_______________________________________________
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: 
 >Subclassing From Code? (From: David McGavern <email@hidden>)

  • Prev by Date: Re: Programming a game
  • Next by Date: Re: Subclassing From Code?
  • Previous by thread: Subclassing From Code?
  • Next by thread: Re: Subclassing From Code?
  • Index(es):
    • Date
    • Thread