ios - 将 Swift 添加到项目中会显着增加大小。如何以及何时可以避免

标签 ios swift

我有一个用 Objective-C 编写的小应用程序。它的大小约为 3 Mb。 当我添加一个 Swift 文件时,我的存档大小增加到 10 Mb。

我发现 Swift 在每个使用它的项目中嵌入了它的实际库。即使将来 Swift 库发生变化,这也是能够运行该项目所必需的。

但是 8 MB 对于小型项目来说是一个巨大的开销。也许有一些关于 Swift 何时获得嵌入操作系统的稳定库的信息?

或者也许可以添加一些标志到项目中,强制编译器使用 iOS 中嵌入的标准 Swift 库?

最佳答案

Swift 仍在变化。因此,目前每个应用程序都必须包含运行时。一旦 Swift 的开发放缓,也许苹果会在 iOS 中包含 Swift 运行时。

自 6.0 测试版以来,几乎每次发布 Xcode 后,都必须调整 Swift 源代码。运行时与编译器同时发生变化。 iOS 无法使用标准 swift 库,但必须使用编译和链接应用程序的库。

参见this explanation by Apple .

you can trust that your app will work well into the future. In fact, you can target back to OS X Mavericks or iOS 7 with that same app. 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

While your app’s runtime compatibility is ensured, the Swift language itself will continue to evolve, and the binary interface will also change.

As Swift changes, those frameworks will be incompatible with the rest of your app. When the binary interface stabilizes in a year or two, the Swift runtime will become part of the host OS and this limitation will no longer exist

不使用 Swift 是缩小应用大小的唯一方法。

Swift 3.0 won't deliver a stable ABI ,暂时保持不变。因此,一两年内可能会转化为 2018 年的 Swift 5.0。

关于ios - 将 Swift 添加到项目中会显着增加大小。如何以及何时可以避免,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57787444/

相关文章:

ios - 使用 swifts guard 语句进行多值检查?

json - Swift:来自 URL 而不是本地的 JSON 文件

ios - 未安装 CocoaPods。跳过 pod 安装

ios - 使用标签栏 Controller-> Nav controller -> View Hierarchy 从 app delegate 呈现 View - iOS Swift

ios - 与后面的 View Controller 交互

android - Json VS SQLite 哪个更适合Android/iOS开发

swift - macOS:有没有办法在不崩溃的情况下访问窗口 Controller ?

ios - 两个不同的 UIButton 中的日期选择器更新值

swift - 使用swift在firebase中搜索子子

快速查询如何检测是否没有找到结果?