Re: What alternatives exist for objc_setClassHandler?
Re: What alternatives exist for objc_setClassHandler?
- Subject: Re: What alternatives exist for objc_setClassHandler?
- From: Michael Ash <email@hidden>
- Date: Sat, 31 Jan 2009 23:47:38 -0500
On Sat, Jan 31, 2009 at 6:33 PM, Andrew Thompson <email@hidden> wrote:
> 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?
Yes, I just meant that you register ahead of time. I agree that it's
clunky and annoying, but it seems to me that it's not *too* bad, and I
don't see a better way. Hopefully you know which classes can get
bridged, so you can bridge them ahead of time. As far as I know there
is no API to get the classes out of a nib at runtime. You *might* be
able to do it with ibtool at compile time and thus somewhat automate
it that way, with some scripting and such to build some data you can
use to load your classes, but I really haven't look at it.
And as always, file an enhancement request at bugreport.apple.com
about this missing API. They may have removed it thinking that nobody
actually uses it, and if you inform them otherwise there is a chance
(however slight) that they will change their minds for some future OS
release.
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