6

The article https://developer.xamarin.com/guides/cross-platform/macios/binding/ mentions how a native library written using Objective-C can be used in Xamarin. Is there any documentation available for doing the same with a native framework written in Swift? https://developer.xamarin.com/guides/ios/advanced_topics/embedded_frameworks/ talks about using embedded frameworks but it does not say anything about swift. Does the same thing work?

famousgarkin
  • 13,687
  • 5
  • 58
  • 74
Amruta
  • 425
  • 4
  • 16
  • Swift does not support creating static `.a` libraries, it only supports Framework creation. The only way that I currently know of is to create an ObjC static library and expose your Swift Framework via ObjC-based functions and then you can bind that to C#. – SushiHangover May 24 '16 at 05:03
  • @SushiHangover - if a project has any swift reference,then it can not be translated into .a library right ! but if it uses swift framework then its not the problem we can convert it into .a library.Correct me If I am wrong !If you have any working sample hosted in Github or something kindly consider sharing it – Durai Amuthan.H Mar 29 '17 at 09:43
  • @DuraiAmuthan.H I'm not sure what you mean... – SushiHangover Mar 29 '17 at 19:10
  • @SushiHangover - you have mentioned we can import a swift framework and we can expose Swift APIs through Objective C... and so we can get .a static library and which will be used for binding...Is my understanding right ? – Durai Amuthan.H Mar 29 '17 at 21:59

2 Answers2

4

Binding Swift libraries is not officially supported, but you can find a documentation on how to do it:

https://medium.com/@Flash3001/binding-swift-libraries-xamarin-ios-ff32adbc7c76

Lucas Teixeira
  • 704
  • 8
  • 11
0

Sorry to reopen a death thread, but binding Swift library is now officially supported by Xamarin.

https://learn.microsoft.com/en-us/xamarin/ios/platform/binding-swift/walkthrough

The procedure is very similar than the one needed to bind Objective-C libraries. In fact, Swift is compatible only with Swift, and a Swift framework to be accessible to Objective-C or Xamarin needs to export Objective-C headers.