How to create binding of Xamarin ios swift library with multiple dependencies

Hamid Abdullah 6 Reputation points
2021-04-02T04:00:00.177+00:00

I'm trying to make binding of swift library frames-ios which has two dependencies PhoneNumberKit and Alamofire as mentioned in package.swift file. I have searched a lot but not found any example of it. I have followed Binding a swift Framework but they are using Gigya.framework package as demonstration and I have not found any package with framework extension in git repository of frames-ios. So what I did I used cocoapods to add required dependencies but the project faild to build with showing error "Directory not found 'Frames'" and similar errors for other dependencies. For this I followed adding a third party framework inside a first party framework in xcode and related threads on stackoverflow but unable to solve the issues.

In my last try, I added frames-ios using Package Manager that is very handy which automatically includes required dependencies and I'm also able to successfully build and bind using sharpie but the resulted ApiDefinitions.cs and StructsAndEnums.cs files contains 4 to 5 thousand lines of code each of them and with full of errors. I think this is not correct way of binding and contains definitions from dependencies in these two files.

At the end, I want to mention that I followed almost all relevant posts and approaches available for Xamarin ios binding but unable to bind this library so someone can guid me please to bind such libraries

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,296 questions
0 comments No comments
{count} vote

2 answers

Sort by: Most helpful
  1. Cole Xia (Shanghai Wicresoft Co,.Ltd.) 6,751 Reputation points
    2021-04-16T03:09:31.59+00:00

    Hello,

    Welcome to Microsoft Q&A!

    For binding Swift with Xamarin.iOS, you will need to decorate"@objc" on the Swift methods that they want to bind over to C#. All methods decorated with "@objc" will be compiled into the Objective-C header, which will determine what will be included in the bindings. As this step has not already been done by the library owner, you can use the usage instructions on the Frames GitHub to determine what methods they will need to directly call in C#. Those methods are the ones they will need to add "@objc" to. Source : https://github.com/checkout/frames-ios#usage .

    You can refer to the Build a native library section of our walkthrough. Step 9 includes an example of how to decorate methods with "@objc". They can skip any mention of the Gigya.framework, as their project has access to the source Swift files and does not require referencing a framework. If they follow the steps, they should generate a Frames framework and Frames Obj-C header file which they can then use for the rest of the binding process.
    Source: https://learn.microsoft.com/en-us/xamarin/ios/platform/binding-swift/walkthrough#build-a-native-library

    For the dependencies on AlamoFire and PhoneNumberKit, I see the source GitHubs on those libraries appears to be open source as well. You can likely include the dependencies in their Framework project when generating the Frames framework.


    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

  2. Andrei-Mihai Pop 1 Reputation point
    2021-07-22T10:14:19.38+00:00

    I had the same problem with a framework that has two dependencies. There are two cases here:

    • You do not need anything from those dependencies in your binding library's public interface
      You can add the dependency frameworks in the binding library as Native References.
    • You need those dependencies in your binding library's public interface
      In this case you need to create bindings for those dependencies as well
    0 comments No comments