Creating ABI stable swift libraries

Alberto García
2 min readOct 30, 2021

Swift 5 brought us a bunch of new APIs but in fact one of the most important things was the ABI stability.

iPhone development

What implies ABI stability to the development?

Do you remember the old times (and in 2021 it is still happening) when Xcode magically was updated and you had to request all your third party providers for a new version of their SDK? Well, thats the ABI stability. Before swift 5, every with every new version of swift’s ABI, you had to recompile your code in order to be able to support the latest version of Xcode. This was particularly crucial when Apple forces you to support the newest OS and, with it, the newest ABI.

As I said, from swift 5, you can now have under the same app several versions of the ABI working at the same time.

Yes!! our problems have been solved and now we can forget these old times… Well, not so fast. In order to deploy your code under ABI stability you first have to do some changes to your deployment pipelines and maybe to your code.

How to support ABI stability?

When compiling your project, there’s a new compiler flag called BUILD_LIBRARY_FOR_DISTRIBUTION. By setting this flag to true, you will adopt ABI stability.

Library distribution settings flag

If you don’t want to modify your Xcode project or maybe because you want to ensure it is in your deployment pipeline. When archiving your framework you can specify xcodebuild to generate the artifact with this flag set to true

xcodebuild archive \
-scheme Translations \
BUILD_LIBRARY_FOR_DISTRIBUTION=YES \
SKIP_INSTALL=NO

xcodebuild archive -scheme Translations BUILD_LIBRARY_FOR_DISTRIBUTION=YES SKIP_INSTALL=NO

If you want to know the advantages of distributing compiled code instead of source code, check out my post:

If you like these posts please don’t forget to give me a clap and if you want me to write about another topic, don’t forget to add it to the comments.

--

--