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.
I started by created a new static library using Xcode and defined a 'Calculator' class. Below is the .h and .m
@interface Calculator : NSObject
- (NSString*)getMessage;
@end
@implementation Calculator
- (NSString*)getMessage
{
return @"hey, look at me!";
}
@end
This built into the file 'libXcodeLib.a'. I defined the following MonoTouch bindings for this class and methods:
[BaseType(typeof(NSObject))]
interface Calculator
{
[MonoTouch.Foundation.Export("getMessage")]
string GetMessage();
}
As well as an additional AssemblyInfo.cs for gcc_flags with the following:
[assembly: LinkWith ("libXcodeLib.a", LinkTarget.Simulator | LinkTarget.ArmV6 | LinkTarget.ArmV7, ForceLoad = true)]
And finally, here's a look at the Makefile used to produce the .dll file
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
And here is sample code invoking this method:
var calc = new MTBindings.Calculator();
var msg = calc.GetMessage();
At this point, why is msg NULL?
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!
Thanks to the SO community - I hope :)