Are Swift dynamic libraries backward compatible wi

2020-04-17 06:45发布

问题:

I'm starting to work on a SDK from scratch. I'm not really sure if I should write it in Swift or Objective-C. I feel Swift is better than Objective-C in many aspects, but my major question is - Will swift dynamic libraries support older version of Swift. Say I write my dynamic library in Swift 3.0, will I be able to use that dynamic library in a project using Swift 2.2? I found this in an article I was reading

Dynamic libraries are executable chunks of code that can be linked to an application. This feature allows current Swift applications to link against newer versions of the Swift language as it evolves over time.

Does this mean that I will be able to run a dynamic library built in Swift 3.0 in a project using Swift 2.2? I also found this in Apple documentation

First, Swift 2.3 and Swift 3 are not binary compatible so your app's entire code base needs to pick one version of Swift.

I find this quite contradicting to the first statement. I know importing Objective-C libraries in Swift is pretty straightforward using a bridging header, does the same go for the opposite scenario? Will there be any issues or hurdles I'll step onto when trying to make the Swift library work with Objective-C project. I couldn't find any answers or articles which address backward compatibility. Any help is much appreciated. Thanks!

TLDR: Are dynamic libraries built with Swift 3(or greater) compatible in projects using older versions of Swift or projects in Objective-C

回答1:

Simply put, the first quoted statement is false (currently).

The Swift ABI (application binary interface) is not finalised. The ABI is the set of conventions for how function calls look, how variables and references are stored in a real machine etc. Until it is finalised, all Swift modules in an application have to be compiled with the same version of Swift.

For more information on the Swift ABI, see the Swift ABI Manifesto.