How does an app installed on an older iOS device handle Copy of Swift Runtime?

I am currently trying to understand the following specifications.

Swift.org - Evolving Swift On Apple Platforms After ABI Stability
Will an app built with Swift 5 run on any version of macOS before 10.14.4?

Swift 5 does not require apps to raise their minimum deployment target.

Apps deploying back to earlier OS releases will have a copy of the Swift runtime embedded inside them. Those copies of the runtime will be ignored — essentially inert — when running on OS releases that ship with the Swift runtime.

For example, I understand that if I create an iOS app using Swift 5 or later and install that app on an older iOS device (e.g. iOS11), a copy of the Swift runtime will be embedded in that app.

At this point, I have two questions.

The first question is: Is this copy of the swift runtime created for each app?
For example, if I install 100 similar apps, does each one of those apps have a copy of the Swift runtime?
If the Swift Runtime copies were 20 MB, would they consume 20 MB * 100 ?

The second question is: When using Swift 5 or later, is there a case where "ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES=YES" is required in Xcode?

I hope someone knows the answer.
Thanks.

Is this copy of the swift runtime created for each app?

Yes. The runtime is embedded within the app (in the Frameworks directory) and each app gets its own copy.

I vaguely recall that the App Store is smart enough to remove this if you install the app on a system that has the runtime built in, but I’ve no idea where I saw that and it’s not easy to test empirically.

When using Swift 5 or later, is there a case where
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES=YES is required in Xcode?

Yes. If you have an app built entirely in Objective-C that has embedded app extensions that uses Swift, you’ll need to set ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES in the app target so that Xcode knows to embed the Swift runtime there for the benefit of the app extensions.

Share and Enjoy

Quinn “The Eskimo!” @ DTS @ Apple

1 Like

You can observe this obliquely using App Store Connect’s variant build size report, where devices that came out with iOS 13 or later have smaller app sizes even if you haven’t defined any variant resources. This doesn’t prove that it also happens on older devices, but it does (and you can verify in the Storage settings for your device).

1 Like

I think it's 12.2, FWIW. https://developer.apple.com/documentation/xcode-release-notes/swift-5-release-notes-for-xcode-10_2#App-Thinning

2 Likes

@eskimo

Is this copy of the swift runtime created for each app?

Yes. The runtime is embedded within the app (in the Frameworks directory) and each app gets its own copy.

When using Swift 5 or later, is there a case where
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES=YES is required in Xcode?

Yes. If you have an app built entirely in Objective-C that has embedded app extensions that uses Swift, you’ll need to set ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES in the app target so that Xcode knows to embed the Swift runtime there for the benefit of the app extensions.

Thanks.
I don't like the behavior of having a copy per app, but unfortunately I get it.

We expect Swift Standard Libraries included by "ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES=YES" to be removed by App thinning in iOS 12.2 or later if not needed.
We are currently discussing this with Apple Developer Technical Support (DTS).