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

标签 ios swift

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

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

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

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

最佳答案

Swift 仍在变化。所以目前运行时必须包含在每个应用程序中。一旦 Swift 的开发速度放缓,Apple 可能会在 iOS 中包含 Swift 运行时。

自 6.0 beta 以来,几乎每次 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/28275711/

相关文章:

ios - 如何在 Swift 中使用 JTCalendar?

ios - 如何将 UISlider 添加到不是 View Controller 主场景的 SKScene

ios - 如何在 IOS swift 应用程序中启用堆栈粉碎保护?

ios - 由于未捕获的异常 'NSUnknownKeyException' 而终止应用程序,原因 : this class is not key value coding-compliant for the key Label2. '

ios - 获取 Firebase 文档对象作为 Swift 对象

iOS 13 safaridriver 无法创建 safari session

ios - 无法导航到 iOS 9 中的其他屏幕

restkit 中的 ios NSDateFormatter

arrays - 如何按属性值(日期)对包含 NSManagedObject 子类实例的快速数组进行排序

ios - UserNotifications 显示过去的时间(例如 : 2 minutes ago)