Darren
Darren

Reputation: 10398

Please explain the purpose of Always Embed Swift Standard Libraries

I thought I understood what Always Embed Swift Standard Libraries was doing, but now i'm confused.

I pushed an update to a MacOS app to the App Store and a user said it was crashing for him on macOS High Sierra. After a very quick investigation, it seems the swift libraries were missing and one of my frameworks was written in swift (Main app was ObjC). I switched Always Embed Swift Standard Libraries to YES, re-uploaded a new build and everything was great with the world.

I have now uploaded a brand new iOS app to Testflight that is build for iOS 9.3+ and remembered about this issue so thought i'd test it out. The Always Embed Swift Standard Libraries setting is set to NO which must have been the Xcode default. I downloaded the app through TestFlight on an iOS 9.3.2 device expecting it to crash on launch, but no, the app works perfectly fine.

How can a macOS app crash running on 1 major version behind of macOS but an iOS app can run perfectly fine on iOS that's 4 major versions behind?

Am I completely misunderstanding what this setting does?

When should we use Always Embed Swift Standard Libraries?

----- EDIT I've just checked the .app contents and it seems it does have the swift libraries in it, which would explain why t didn't crash on iOS 9.3.2. So an additional question. Why would the swift libraries be there when Always Embed Swift Standard Libraries is set to NO?

Upvotes: 20

Views: 7115

Answers (1)

Andreas Oetjen
Andreas Oetjen

Reputation: 10209

I had to read the documentation several times, to get a clue what's going on:

Always Embed Swift Standard Libraries (ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES)

Always embed the Swift standard libraries in the target's products, even if the target does not contain any Swift code.

This means

  • if you set ALWAYS... to YES, the libraries will definitely be embedded.
  • if you set it to NO, they will not always be embedded - they might or might not be embedded, regarding of how clever the build system is able to decide that it needs them or nor (depending on the target version or so).

This is a common misinterpretation: The negation of always is not never, it is just not always (e.g. sometimes or so).

Upvotes: 16

Related Questions