Forum Xamarin.iOS

Xamarin does NOT support Binding iOS SWIFT FRAMEWORK to CSharp?

BrightLeeBrightLee KRMember ✭✭✭
edited August 2016 in Xamarin.iOS

I'm trying to binding this iOS native to Xamarin.iOS library.

this is what I've done so far.

  1. I created embedded framework from this (**SWIFT LIBRARY) :

  2. I created Xamarin library with that framework and bind it to CSharp.(Wrapping)

  3. I success to build Xamarin library.

  4. getting runtime Error :

Could not create an native instance of the type 'nRF5xDFULibrary_Xamarin_iOS.DFUServiceInitiator': the native class
hasn't been loaded. It is possible to ignore this condition by setting ObjCRuntime.Class.ThrowOnInitFailure to false.

Now, I ran into this thread :

Our existing binding tools do not work with Swift. If you have a way to bring this into Obj-c headers, then tooling like Objective Sharpie can consume it and create a binding definition. However, we don't currently support using a Swift library, so your mileage may vary.

I'm getting error because it's a framework made by Swift? If so, I'm really screwed.

Can you give me any advice?

Best Answer


  • DaveHuntDaveHunt USMember ✭✭✭✭✭
    edited August 2016

    If the library isn't compiled for whatever target platform you're running on, you'll get that error. For example, if you're trying to run on the simulator, the binary needs to have an x86 and/or an x86_64 slice. See for reference. Not sure how that works with Swift, but it should give you a starting point.

  • BrightLeeBrightLee KRMember ✭✭✭

    OK Thanks for answering my question @JohnMiller .
    Could I know any information about progress that you guys're working on that(supporting binding Swift)?
    So that I can decide weather I can stop here or not.

  • BrightLeeBrightLee KRMember ✭✭✭

    Oh, @DaveHunt . I believed I did make Fat framework.
    I built that framework by this way :

    Universal framework mentioned by that link, is not same with Fat binary?
    If so, I will have to do it again with following document you gave.


    But as John says, Xamarin is not supporting binding Swift Library at this moment.

  • DaveHuntDaveHunt USMember ✭✭✭✭✭

    John says their current tooling doesn't support generating bindings for Swift. That's not the same as not being able to do it.

    You may have created a fat binary, but you may not have included all the necessary architectures for wherever you're trying to run it.

  • BrightLeeBrightLee KRMember ✭✭✭

    Thanks again for answering my question.
    I don't quiet understand what you said but sounds like a good news.
    If you don't mind, could you check my binded library?


    weird thing is, I'm sure all source code is written by Swift.

    But built framework's header file is Objc. What's the deal? is it natural?

  • DaveHuntDaveHunt USMember ✭✭✭✭✭

    When the creator of the framework includes @objc prefixes on externally accessible objects/methods/etc, an Obj-C header isautomatically created to provide an interface to those methods. Without that, you would not be able to call them from Obj-C or create bindings for Xamarin.

    I can't tell from your project whether you created a fat binary with all the necessary architectures. The link I provided you shows how to do that using a Makefile and Xcode.

  • BrightLeeBrightLee KRMember ✭✭✭
    edited August 2016

    My framework has arm, arm64, x86_64 achitectures. It's working fine on simulator and device when I tested with importing this framework to my original iOS Native app with XCode. So I thought it's fat framework.

    The link you gave me is dealing with .a library to combine those achitectures.
    I'm sure it's same with I've done to my framework.
    You can see my framework filefolder which I created.
    here :

    in github,

    Thanks again. @DaveHunt

  • DaveHuntDaveHunt USMember ✭✭✭✭✭

    Unfortunately, I'm at work where we don't have Macs, so there's not much I can look at.

  • BrightLeeBrightLee KRMember ✭✭✭

    Thanks though!

  • ArashDavidiArashDavidi USMember ✭✭

    Hey @BBright ,

    Hope you already succeeded to make static obj-c library that bind a swift framework and expose it with an obj-c header, So Objective Sharpie could do the wrapping stuffs, have you?

  • BrightLeeBrightLee KRMember ✭✭✭


    Hi Arash.
    I'm sorry.
    I stopped digging more at that point.
    I don't use obj-c static library nor swift library currently.

  • Abhi.7519Abhi.7519 USMember ✭✭

    Anyone have Idea about IOS DFU with Xamarin. or any reference code

  • BrightLeeBrightLee KRMember ✭✭✭


    Hey Abhi, if you're using nordic chip for ble communication,
    please check this thread.

  • eubikeubik Member ✭✭

    @JohnMiller or anyone else who may know - Is it still the case that binding Swift libraries is not supported?

    I haven't found any Xamarin/Microsoft documentation on it, but wanted to make sure. Thanks!

  • R you still looking for Swift library integration? I found this while I am looking for Swift library integration and it worked pretty good for me.

    _I had to integrate ObjectiveC Code (which had some swift libraries in it) with my Xamarin iOS Project. _

Sign In or Register to comment.