Note that there are some explanatory texts on larger screens.

plurals
  1. POMonoTouch/Obj-C Binding How-To
    primarykey
    data
    text
    <p>I'm working to create bindings for Obj-C library so that I can work together with another team together on same project. To ensure this works, I'm attempting to create a simple obj-c library, define bindings, and use that object within MonoTouch. I have no build issue or even runtime exceptions, but my return value from calling any function is always null.</p> <p>I started by created a new static library using Xcode and defined a 'Calculator' class. Below is the .h and .m</p> <pre><code>@interface Calculator : NSObject - (NSString*)getMessage; @end @implementation Calculator - (NSString*)getMessage { return @"hey, look at me!"; } @end </code></pre> <p>This built into the file 'libXcodeLib.a'. I defined the following MonoTouch bindings for this class and methods:</p> <pre><code> [BaseType(typeof(NSObject))] interface Calculator { [MonoTouch.Foundation.Export("getMessage")] string GetMessage(); } </code></pre> <p>As well as an additional AssemblyInfo.cs for gcc_flags with the following:</p> <pre><code>[assembly: LinkWith ("libXcodeLib.a", LinkTarget.Simulator | LinkTarget.ArmV6 | LinkTarget.ArmV7, ForceLoad = true)] </code></pre> <p>And finally, here's a look at the Makefile used to produce the .dll file</p> <pre><code>BTOUCH=/Developer/MonoTouch/usr/bin/btouch all: XcodeLib.dll XcodeLib.dll: Makefile ApiDefinition.cs AssemblyInfo.cs libXcodeLib.a $(BTOUCH) -e ApiDefinition.cs AssemblyInfo.cs --out=XcodeLib.dll --link-with=libXcodeLib.a,libXcodeLib.a </code></pre> <p>And here is sample code invoking this method:</p> <pre><code>var calc = new MTBindings.Calculator(); var msg = calc.GetMessage(); </code></pre> <p><strong>At this point, why is msg NULL?</strong></p> <p>From all the reading I've done, I cannot see what I'm missing to make this work. Any newer or proven samples/tutorials would be greatly appreciated, I'm not sure how to simplify this more - and yet it still doesn't work!</p> <p>Thanks to the SO community - I hope :)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload