Xamarin Binding from native Swift iOS framework

StefanFaustStefanFaust Member
edited August 9 in Xamarin.iOS

I adopt my Xcode project with @objc tags so I can use that methods into Xamarin binding. I added .framework as native library to project (also tried to add .a library but I got same problem). I used sharpie bind and created ApiDefinition.cs and Struct.cs, solve all errors there, and when I tried to build it I got a lot of error like:
Error CS0246: The type or namespace name 'PageTracker' could not be found (are you missing a using directive or an assembly reference?) (CS0246) (WebtrekkSDKBinding)
I found that swift code confused Xamarin, because page tracker is defined: @objc
public protocol PageTracker: class. So Xamarin do not have in obj folder PageTracker class, only IPageTracker and PageTrackerWrapper. I don't know how to change Swift code, so it will start working.
Can someone help me? :(

Thanks in advance.

Best Answer

  • Accepted Answer

    Hi guys, I found the solution. I was need to change ApiDefiniton.cs file, to be more specific add name from Objective-C runtime.
    Into PROJECTNAME-Swift.h which you can be find at PROJECTNAME.framework file. For example I changed this:

    [BaseType(typeof(NSObject)] interface MyClass

    to:

    [BaseType(typeof(NSObject), Name = “_TtC11SwiftSample7MyClass”)] interface MyClass

Answers

  • StefanFaustStefanFaust Member
    Accepted Answer

    Hi guys, I found the solution. I was need to change ApiDefiniton.cs file, to be more specific add name from Objective-C runtime.
    Into PROJECTNAME-Swift.h which you can be find at PROJECTNAME.framework file. For example I changed this:

    [BaseType(typeof(NSObject)] interface MyClass

    to:

    [BaseType(typeof(NSObject), Name = “_TtC11SwiftSample7MyClass”)] interface MyClass

Sign In or Register to comment.