[Mono-osx] external reference to a class

Laurent Etiemble laurent.etiemble at gmail.com
Fri Nov 6 02:53:54 EST 2009


Why don't you use the "NSClassFromString" function
? The return type is a Class instance, and is not as low-level as a
call to objc_getClass().

[NSClassFromString(@"MyMonoClass") testTouch];

Note 1: See http://www.cocoadev.com/index.pl?NSClassFromString for more comments
Note 2: you can even define a macro to avoid the cluttering of your code.

Regards, Laurent Etiemble.

2009/10/22 Duane Wandless <duane at wandless.net>:
> Hopefully someone can help with this.
> I am currently doing this.
>     id myobj = objc_getClass("MyMonoClass");
>     [myobj testTouch];
> which works.  MyMonoClass is not defined so I cannot do this:
> [MyMonoClass testTouch];
> Because the compiler tries to resolve the class reference, of course.
> Is there a better way to do this than what I have?  Which I got the idea of
> how to do this from Monobjc!
> The context is that I have a Cocoa application that loads the mono runtime
> which loads my Monobjc enabled library.  Which that is where MyMonoClass is
> defined.  Then I need to invoke a method on the mono class from Cocoa.
> Thanks,
> Duane
> _______________________________________________
> Mono-osx mailing list
> Mono-osx at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-osx

More information about the Mono-osx mailing list