4.7.6.4 Defining the API contract

An Objective-C header file is provided. To use the library from within a .NET project, you have to link the library's interface parts to .NET structures.

Linking is done in the file ApiDefinition.cs. You have to translate the header file contents into some C# interfaces. Finally you have to annotate the interfaces/methods/parameters that name the library's objects.

Detailed information about translation and annotation may be found on Xamarins web site: http://docs.xamarin.com/ios/Guides/Advanced_Topics/Binding_Objective-C_Libraries.

To use the library, adapt the following:

Library's header file content Linking in ApiDefiniton.cs
@interface ObjCClass  
... [BaseType (typeof (NSObject))]
  interface ObjCClass {
@end ...
  }
+(void)method1:(int)parameter; [Static, Export(''method1:'')]
  void method1(int parameter);
-(NSString$\ast$)method2; [Export''method2'')]
  NSString method2();
@protocol MyDelegate  
-(int)method3;  
@end [BaseType (typeof(NSObject))]
  [Model]
  interface MyDelegate {
  [Export(''method3'')]
  [Abstract]
  int method3();
  }



Copyright BREDEX GmbH 2014. Made available under the Eclipse Public License v1.0.