How to use swift framework in xamarin ios app development

We have developed cocoa touch framework using swift code, I need to use that framework in my xamarin ios app.
Thanks.

Tagged:

Posts

  • RaymondLe2409RaymondLe2409 VNMember

    please help them and me :smile:

  • DaveHuntDaveHunt USMember ✭✭✭✭✭

    There is currently no support for linking with Swift frameworks.

  • JKLTechnologiesJKLTechnologies USMember
    edited June 2016

    @DaveHunt , i download sample framework from github and created binding project in xamarin IOS, used that framework,finally that .dll file is working fine, but i developed a framework project in Xcode IDE and it's not working.

  • DaveHuntDaveHunt USMember ✭✭✭✭✭

    @JKLTechnologies

    If the Swift framework you want to use wasn't created with plans for calling into it from Objective-C (i.e. tagging classes with the @objc keyword), then you're not going to be able to use it from C# either. There's not a lot Xamarin can do about that.

    If all the public classes/interfaces are properly tagged, then you could potentially get it to work because you'll have an Xcode-generated header file to use for creating the binding. But there's still no guarantee. Your mileage may vary.

  • JKLTechnologiesJKLTechnologies USMember

    @DaveHunt , we have attached sample project with use of framework, we download framework its basically developed in objective-c and its working fine in my project.
    Please look at this link:https://dropbox.com/s/4speg5s8etc8j5n/TestWithDownloadFramework.zip?dl=0

    We have developed our own iOS Framework project, going to use in xamarin iOS app development its throw exception.
    we have attached exception screenshot also.

    Please look at this link : https://dropbox.com/s/2oyf93cdvdcjcq7/TestWithMyFrameworkCons.zip?dl=0

    One more project that will have only static methods , if we call that methods without any error or exception its running but main problem is weather the method are calling or not, if it is calling why is not working....

    Please look at this link : https://dropbox.com/s/czuduk4z984lj9b/TestWithMyFramework.zip?dl=0

  • DaveHuntDaveHunt USMember ✭✭✭✭✭

    @JKLTechnologies

    I'm sorry, but I don't have time to download and analyze your projects. Please refer to my previous post. If care is taken when creating the Swift-coded framework so that all externally accessible classes are properly tagged as @objc, then you may be able to generate a C# binding and use it in a Xamarin project. If the Swift classes aren't properly tagged,, then you definitely will not be able to use it in a Xamarin project.

  • JKLTechnologiesJKLTechnologies USMember
    edited June 2016

    @DaveHunt
    import Foundation
    @objc public class MySwiftClassTest: NSObject
    {
    @objc public init(num:Int){
    print ("Initiating the object");
    }
    @objc public func viewMethod(num:Int){
    print("Received msg from (num)");
    }
    @objc public static func CallMethod(){
    print("call method print");
    }
    }

    Everything tagged "@objc" properly but still have the problem it throwing exceptions.

    Exception:
    Unhandled Exception:
    System.Exception: Could not create an native instance of the type 'Binding7FW.MySwiftClassTest': the native class hasn't been loaded.
    It is possible to ignore this condition by setting ObjCRuntime.Class.ThrowOnInitFailure to false.
    at Foundation.NSObject.InitializeObject (Boolean alloced) [0x000b9] in /Users/builder/data/lanes/3234/d8bedd03/source/maccore/src/Foundation/NSObject2.cs:187
    at Foundation.NSObject..ctor (Foundation.NSObjectFlag x) [0x0000d] in /Users/builder/data/lanes/3234/d8bedd03/source/maccore/src/Foundation/NSObject2.cs:114
    at Binding7FW.MySwiftClassTest..ctor (nint num) [0x00000] in /Users/jkltechconnect/Projects/BindingWithNativeFrame/Binding7FW/obj/Debug/ios/Binding7FW/MySwiftClassTest.g.cs:76
    at MyTest.ViewController.BtnSave_TouchUpInside (System.Object sender, System.EventArgs e) [0x00012] in /Users/jkltechconnect/Projects/BindingWithNativeFrame/MyTest/ViewController.cs:31
    at UIKit.UIControlEventProxy.Activated () [0x00007] in /Users/builder/data/lanes/3234/d8bedd03/source/maccore/src/UIKit/UIControl.cs:37
    at (wrapper managed-to-native) UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
    at UIKit.UIApplication.Main (System.String[] args, IntPtr principal, IntPtr delegate) [0x00005] in /Users/builder/data/lanes/3234/d8bedd03/source/maccore/src/UIKit/UIApplication.cs:77
    at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0001c] in /Users/builder/data/lanes/3234/d8bedd03/source/maccore/src/UIKit/UIApplication.cs:60
    at MyTest.Application.Main (System.String[] args) [0x00008] in /Users/jkltechconnect/Projects/BindingWithNativeFrame/MyTest/Main.cs:12
    2016-06-09 13:46:50.550 MyTest[1404:57754] Unhandled managed exception:
    Could not create an native instance of the type 'Binding7FW.MySwiftClassTest': the native class hasn't been loaded.
    It is possible to ignore this condition by setting ObjCRuntime.Class.ThrowOnInitFailure to false. (System.Exception)
    at Foundation.NSObject.InitializeObject (Boolean alloced) [0x000b9] in /Users/builder/data/lanes/3234/d8bedd03/source/maccore/src/Foundation/NSObject2.cs:187
    at Foundation.NSObject..ctor (Foundation.NSObjectFlag x) [0x0000d] in /Users/builder/data/lanes/3234/d8bedd03/source/maccore/src/Foundation/NSObject2.cs:114
    at Binding7FW.MySwiftClassTest..ctor (nint num) [0x00000] in /Users/jkltechconnect/Projects/BindingWithNativeFrame/Binding7FW/obj/Debug/ios/Binding7FW/MySwiftClassTest.g.cs:76
    at MyTest.ViewController.BtnSave_TouchUpInside (System.Object sender, System.EventArgs e) [0x00012] in /Users/jkltechconnect/Projects/BindingWithNativeFrame/MyTest/ViewController.cs:31
    at UIKit.UIControlEventProxy.Activated () [0x00007] in /Users/builder/data/lanes/3234/d8bedd03/source/maccore/src/UIKit/UIControl.cs:37
    at (wrapper managed-to-native) UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
    at UIKit.UIApplication.Main (System.String[] args, IntPtr principal, IntPtr delegate) [0x00005] in /Users/builder/data/lanes/3234/d8bedd03/source/maccore/src/UIKit/UIApplication.cs:77
    at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0001c] in /Users/builder/data/lanes/3234/d8bedd03/source/maccore/src/UIKit/UIApplication.cs:60
    at MyTest.Application.Main (System.String[] args) [0x00008] in /Users/jkltechconnect/Projects/BindingWithNativeFrame/MyTest/Main.cs:12
    2016-06-09 13:46:50.551 MyTest[1404:57754] critical: Stacktrace:

  • DaveHuntDaveHunt USMember ✭✭✭✭✭

    That looks like a problem with your binding project. That's about all I can tell from what you've posted.

Sign In or Register to comment.