swift生成的IPA太大了,大约5MB

IPA generated by swift is so big, about 5MB

我刚刚使用 swift 语言创建了一个简单的项目,然后我编译并存档它以生成 .ipa 文件。 IPA文件很大,大约5MB。

那里对吗(没问题)?当我在 Objective-C 中创建它时,它只有大约 500kb。

是的,差不多是这样。包含整个 Swift 语言的库必须嵌入到 IPA 中。这些库是应用程序的一部分,而不是系统的一部分 - 因为 Swift 即使具有向后兼容性也必须工作,部分原因是它不断变化(独立于系统更新),部分原因是为了继续工作iOS7(这里系统没听说过Swift)。它们的大小约为 5MB。

为了扩展马特的回答,这里引用了the Swift blog on compatibility

You can trust that your app will work well into the future. […] This is possible because Xcode embeds a small Swift runtime library within your app’s bundle. Because the library is embedded, your app uses a consistent version of Swift that runs on past, present, and future OS releases.

因此,如果您的最新应用版本是使用 Xcode 6.0 构建的,并且您的应用的用户是 运行 iOS 8.1,并且对 Swift 的重大更改是在此期间引入您的应用程序,您的应用程序不会因 iOS 更新而中断。如果您的应用只使用系统库,它可以。

这允许 Swift 的开发人员更快地迭代,而无需在每个版本之间建立向后兼容性。

附加警告:

While your app’s runtime compatibility is ensured, the Swift language itself will continue to evolve, and the binary interface will also change. To be safe, all components of your app should be built with the same version of Xcode and the Swift compiler to ensure that they work together.