external reference to a class

View: New views
3 Messages — Rating Filter:   Alert me  

external reference to a class

by duanew :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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@...
http://lists.ximian.com/mailman/listinfo/mono-osx

Re: external reference to a class

by Laurent Etiemble :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello,

Why don't you use the "NSClassFromString" function
(http://developer.apple.com/mac/library/documentation/cocoa/Reference/Foundation/Miscellaneous/Foundation_Functions/Reference/reference.html#//apple_ref/c/func/NSClassFromString)
? 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@...>:

> 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@...
> http://lists.ximian.com/mailman/listinfo/mono-osx
>
>
_______________________________________________
Mono-osx mailing list
Mono-osx@...
http://lists.ximian.com/mailman/listinfo/mono-osx

Re: external reference to a class

by duanew :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

That is much better... thank you for suggesting this.
Duane

On Fri, Nov 6, 2009 at 2:53 AM, Laurent Etiemble <laurent.etiemble@...> wrote:
Hello,

Why don't you use the "NSClassFromString" function
(http://developer.apple.com/mac/library/documentation/cocoa/Reference/Foundation/Miscellaneous/Foundation_Functions/Reference/reference.html#//apple_ref/c/func/NSClassFromString)
? 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@...>:
> 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@...
> http://lists.ximian.com/mailman/listinfo/mono-osx
>
>


_______________________________________________
Mono-osx mailing list
Mono-osx@...
http://lists.ximian.com/mailman/listinfo/mono-osx