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

iSh*_*war 11 objective-c ios swift

由于Swift支持与目标c的混合匹配,因此我们可以使用它来构建部署目标小于iOS 7的应用程序.

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

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.
Run Code Online (Sandbox Code Playgroud)

因此,在阅读完之后,我脑海中的问题就出现了

  1. 我们可以将swift用于我们目前正在开发的应用程序.
  2. 如果答案是否定则则与上述说明相矛盾.

Ani*_*ese 7

更新 - 根据Xcode 6 Beta 4

iOS 7和OS X 10.9最低部署目标

Swift编译器和Xcode现在强制实施iOS 7或OS X Mavericks的最低部署目标.设置较早的部署目标会导致构建失败.

来自Xcode 6发行说明

所以我之前的回答(如下所示)将不适用于任何进一步的快速发展.iOS版及更低版本将不再提供Swift


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

因此,如果您没有使用作为iOS8 SDK的一部分添加的任何新API或一些特定的快速API(相应的API不适用于ObjectiveC),您的应用程序将无缝地在iOS6 +(经过测试和工作)甚至iOS5(未经测试)上工作.其中的大多数API swift只是现有ObjectiveC API的替代品.实际上它们在二进制中是相同的.



Ole*_*nyk 0

不可以,仅限 iOS 7+ 和 OS X 10.9+。