ios - 我们可以在部署目标低于 iOS 7 的应用程序中集成 swift 代码吗?

标签 ios objective-c swift

由于 Swift 支持与 objective-c 的混合匹配,那么我们可以使用它来构建部署目标低于 iOS 7 的应用程序。

来自 Swift Prerelease Documentation在基本设置部分,我读到的是:

Swift is designed to provide seamless compatibility with Cocoa and Objective-C. You can use Objective-C APIs
(ranging from system frameworksto your own custom code) in Swift, and you can use Swift APIsin Objective-C.
This compatibility makes Swift an easy, convenient, and powerful tool to integrate into your Cocoa app
development workflow.
This guide covers three important aspects of this compatibility that you can use to your advantage when
developing Cocoa apps:

 ● Interoperability lets you interface between Swift and Objective-C code, allowing you to use Swift classes
in Objective-C and to take advantage of familiar Cocoa classes, patterns, and practices when writing Swift
code.

 ● Mix and match allows you to create mixed-language apps containing both Swift and Objective-C files that
can communicate with each other.
 ● Migration from existing Objective-C code to Swift is made easy with interoperability and mix and match,
making it possible to replace parts of your Objective-C apps with the latest Swift features.

所以看完这篇文章后,我想到的问题是

  1. 我们可以将 swift 用于我们目前正在开发的应用程序吗 上。
  2. 如果答案是否定的,那么它将与上述矛盾 解释。

最佳答案

更新 - 根据 Xcode 6 Beta 4

iOS 7 and OS X 10.9 minimum deployment target

The Swift compiler and Xcode now enforce a minimum deployment target of iOS 7 or OS X Mavericks. Setting an earlier deployment target results in a build failure.

From Xcode 6 release note

所以我之前的回答(如下所示)将不适用于任何进一步的快速开发。 Swift 将不再适用于 iOS6 及以下版本


是的,你可以。我已经在我的 iOS6 设备 中测试了一个完全用 Swift 编写的简单应用程序,它运行得非常好。正如苹果所说,Swift 代码与 ObjectiveC 代码二进制兼容。它使用相同的编译器和运行时来创建二进制文件。

因此,如果您不使用作为 iOS8 SDK 的一部分添加的任何新 API 或某些 swift 特定的 api(相应的 api 不适用于 ObjectiveC),您的应用程序将在 iOS6+(已测试和工作) 甚至 iOS5(未测试)。 swift 中的大多数 API 只是对现有 ObjectiveC api 的替换。事实上,它们在二进制中是相同的。


关于ios - 我们可以在部署目标低于 iOS 7 的应用程序中集成 swift 代码吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24037904/

相关文章:

ios - 如何在 iOS 上突出显示多个文本片段?

iphone - 无法解析 XML iPhone

ios - SKCameraNode 跟不上移动节点

ios - 如何在 Swift 4 中按顺序执行操作

ios - 如何在关闭模式后重新加载表格 View

ios - 核心数据 : Parent context and change propagation

javascript - 响应式菜单按钮仅在 iOS 设备上不起作用

iphone - 如何通过Get方法从Web服务中获取数据并想保存到iPhone SDK中的Mutable Dictionary中

iphone - 这个 UI 元素是什么

objective-c - 什么是非脆弱 ABI?