我们可以在部署目标低于 iOS 7 的应用程序中集成 swift 的代码吗? [英] Can we integrate the code of swift in applications having deployment target less than iOS 7?

查看:46
本文介绍了我们可以在部署目标低于 iOS 7 的应用程序中集成 swift 的代码吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

来自 Swift 预发布文档 在基本设置部分下我读的是:

Swift 旨在提供与 Cocoa 和 Objective-C 的无缝兼容.您可以使用 Objective-C API(从系统框架到您自己的自定义代码)在 Swift 中,您可以在 Objective-C 中使用 Swift API.这种兼容性使 Swift 成为一种简单、方便且功能强大的工具,可以集成到您的 Cocoa 应用程序中开发工作流程.本指南涵盖了此兼容性的三个重要方面,您可以利用这些方面的优势开发 Cocoa 应用程序:● 互操作性让您可以在 Swift 和 Objective-C 代码之间建立接口,从而允许您使用 Swift 类在 Objective-C 中,并在编写 Swift 时利用熟悉的 Cocoa 类、模式和实践代码.● 混合搭配允许您创建包含 Swift 和 Objective-C 文件的混合语言应用程序可以互相交流.● 通过互操作性和混合搭配,可以轻松地从现有的 Objective-C 代码迁移到 Swift,使您可以使用最新的 Swift 功能替换部分 Objective-C 应用程序.

所以在阅读本文之后,我脑海中出现的问题是

  1. 我们可以将 swift 用于我们当前工作的应用程序吗上.
  2. 如果答案是否定的,那么它将与上述相矛盾解释.

解决方案

更新 - 根据 Xcode 6 Beta 4

<块引用>

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

Swift 编译器和 Xcode 现在强制执行最低部署目标为 iOS 7 或 OS X小牛队.设置较早的部署目标会导致构建失败.

来自 Xcode 6 发行说明

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


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

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


As Swift supports the mix-match with objective c , then can we use it for building the applications having deployment target less than iOS 7.

from Swift Prerelease Documentation Under the Basic Setup Section what i read is :

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.

So after reading this the questions arrises in my mind are

  1. Can we use swift for the applications we are currently working on.
  2. If the answer is no then it will be contradict to the above explanation.

解决方案

Update - As per 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

So my previous answer(Shown below) will not be applicable to any further swift development. Swift will no longer available for iOS6 and below


Yes you can . I have tested a simple app written completely in Swift in my iOS6 device, it works perfectly fine. As apple says Swift code is binary compatible to ObjectiveC code. It uses the same compiler and runtime to create the binary.

So if you are not using any new APIs added as part of the iOS8 SDK or some swift specific api's (corresponding api is not available for ObjectiveC) your app will seamlessly work on iOS6+(Tested and working) even iOS5(not tested). Most of the APIs in the swift are just the replacement of the existing ObjectiveC api's. In fact they are same in binary.


这篇关于我们可以在部署目标低于 iOS 7 的应用程序中集成 swift 的代码吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆