• 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: What alternatives exist for objc_setClassHandler?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: What alternatives exist for objc_setClassHandler?


  • Subject: Re: What alternatives exist for objc_setClassHandler?
  • From: Andrew Thompson <email@hidden>
  • Date: Sat, 31 Jan 2009 18:33:23 -0500

Thanks... I think I'm with you... kinda of.

So, let's say for the sake of argument I have some NSView subclass implemented in Java: MyView.
In interface builder I drag in a custom view and I set its type to MyView by typing in the name of this class, which doesn't exist as an Objective C class.


When I load that nib file, I'm going to get an error message on the console complaining correctly that MyView doesn't exist.

What I was looking for was a hook from the runtime so I could step in and define some kind of forwarding proxy, which would be the MyView class as far as the objective C runtime was involved, but would "delegate" all functionality to the actual Java class.

objc_setClassHandler would have provided just such a hook. (assuming the name is sufficient to know which class to load, which it usually but not always would be).

Are you proposing instead that the programmer, knowing MyView needs to exist, calls objc_allocateClassPair, class_addMethod and objc_registerClassPair in advance of loading the nib to ensure the classes exist?

That's OK but its a mite clunky. Seems like with most things in obj-c you get notified before a failure occurs so you can step in (e.g. class doesn't respond to message). And indeed this used to exist for undefined classes, but they removed it :(

Unless there's an API to examine a NIB file and see what classes are required to load it? Can NSBundle do that?

AndyT


On Jan 31, 2009, at 5:51 PM, Michael Ash wrote:

On Sat, Jan 31, 2009 at 3:36 PM, Andrew Thompson <email@hidden> wrote:
Hi all,

I was looking for a way to define Objective-C classes at runtime...
specifically to be able to supply class definitions when a Nib file is
loaded. This search soon led me to objc_setClassHandler, but that's listed
as deprecated without replacement here:
http://developer.apple.com/documentation/Cocoa/Reference/ObjCRuntimeRef/Articles/ocr10_5delta.html


What's the story here? Is there a new, preferred way to do this? What are
the Ruby etc. bridges doing?

The bridges don't need this functionality, as they can build the bridging classes as they are created, rather than doing lazy loading. If you can do that as well, that would seem to be an obvious approach. The contents of a nib file shouldn't be a mystery, but should be known ahead of time, so you ought to be able to create all of your classes before you load the nib.

Mike
_______________________________________________

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

AndyT (lordpixel - the cat who walks through walls) A little bigger on the inside

	(see you later space cowboy, you can't take the sky from me)


_______________________________________________

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


  • Follow-Ups:
    • Re: What alternatives exist for objc_setClassHandler?
      • From: Michael Ash <email@hidden>
References: 
 >What alternatives exist for objc_setClassHandler? (From: Andrew Thompson <email@hidden>)
 >Re: What alternatives exist for objc_setClassHandler? (From: Michael Ash <email@hidden>)

  • Prev by Date: elementary CAAnimationGroup question
  • Next by Date: Re: maximum theoretical speedup with dual quad processors
  • Previous by thread: Re: What alternatives exist for objc_setClassHandler?
  • Next by thread: Re: What alternatives exist for objc_setClassHandler?
  • Index(es):
    • Date
    • Thread