I am trying to bind my swift framework with Xamarin. I am using objective Sharpie for this.
sharpie bind -sdk iphoneos11.1 MyFramework.framework/Headers/MyFramework-Swift.h -output=MyFrameworkCS -namespace=MyFramework
I got the APIDefinitions.cs file but its more than 79 thousand lines and has lots of errors. The StructsAndEnums.cs file is huge as well.
My framework(and the .h file) has import statements for only UIKit, AVFoundation and Foundation. But the APIDefinitions.cs has this.
using System;
using AVFoundation;
using AudioToolbox;
using AudioUnit;
using CloudKit;
using CoreAnimation;
using CoreAudio;
using CoreData;
using CoreFoundation;
using CoreGraphics;
using CoreImage;
using CoreLocation;
using CoreMIDI;
using CoreMedia;
using CoreMidi;
using CoreText;
using CoreVideo;
using Darwin;
using Dispatch;
using FileProvider;
using Foundation;
using HyperSecureSDK;
using IOSurface;
using ImageIO;
using Intents;
using MediaToolbox;
using Metal;
using ObjCRuntime;
using ObjectiveC;
using OpenGLES;
using Security;
using UIKit;
using simd;
I am very new to Xamarin and super stuck here. Any help would be greatly appreciated!
You need to define a scope so that not all of the other libraries are showing up in your APIDefinition.cs as stated in https://developer.xamarin.com/guides/cross-platform/macios/binding/objective-sharpie/examples/advanced/
You will notice that we passed a -scope build/Headers argument to Objective Sharpie. Because C and Objective-C libraries must #import or include other header files that are implementation details of the library and not API you wish to bind, the -scope argument tells Objective Sharpie to ignore any API that is not defined in a file somewhere within the -scope directory.
You will find the -scope argument is often optional for cleanly implemented libraries, however there is no harm in explicitly providing it.
This should remove all the bindings of other libraries in your APIDefinition.cs
sharpie bind -sdk iphoneos11.1 -scope MyFramework.framework/Headers/ MyFramework.framework/Headers/MyFramework-Swift.h
-output=MyFrameworkCS -namespace=MyFramework
You need to limit your scope adding the path where the headers are living. Use the -scope
command and library/Headers/
parameter.
eg. sharpie bind -sdk iphoneos11.2 -output myLibrary -scope myLibrary/Headers/ mainHeader.h
Hope can help you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With