2

Why doesn't Swift support static libraries?

I saw this explanation, but I don't understand this reasoning.

The current runtime doesn't ship with the OS, so static libs would lead to multiple runtimes in the final executable. A statically linked runtime would be much more difficult to patch for compatibility with newer OS or Swift. . . . The runtime is in flux. We need to dynamically link it to be able to deal with future forward deployment issues. — Joe Groff

https://twitter.com/owensd/status/555060783407591424

Please explain.

Community
  • 1
  • 1
ma11hew28
  • 121,420
  • 116
  • 450
  • 651
  • Is there any solution using static library in swift 3, I have a encryption library which has only two .a files on vendors sample (written in objective-c ) is working file, When i tried to use those library with using bridging header, (obviously bridging header configuration is fine as other objective-c libs are working fine on ) , it cannot is throwing error. Any one got solution regarding this issue then kindly post some clue. – dip Jun 11 '17 at 04:23

1 Answers1

6

Have you noticed that Swift apps are big? That's because the whole Swift runtime is embedded inside the app. Swift is translated to Objective-C under the hood by the libraries embedded in the app.

The reason for this annoying strategy is that Swift itself is still changing and evolving (Swift 2.2 will go final any day now, revolutionizing the language once again). Thus, Swift cannot be part of the system, like Objective-C; it is in independent flux, at a pace and in a manner that has nothing to do with system updates.

This very state of affairs makes linkage with a static library extremely difficult technically. But dynamic linkage is possible, because it's dynamic.

Later, probably after Swift 3 goes final, the language will at last be frozen and will become part of the system, like Objective-C. Then static libraries will be easier to support, like Objective-C (and Swift apps will get a lot smaller!).

matt
  • 515,959
  • 87
  • 875
  • 1,141