11

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.
iShwar
  • 1,625
  • 1
  • 16
  • 31

7 Answers7

7

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.


Community
  • 1
  • 1
Anil Varghese
  • 42,757
  • 9
  • 93
  • 110
  • 1
    I can confirm that iOS 6 does work as a deployment target (for now), but iOS 5 fails with errors about Swift libraries. – Brad Larson Jul 08 '14 at 00:27
2

I am not sure but YES swift support lower version of ios in to Xcode Beta if you are check in to Project-->Target-->General-->Deplyment Info for select deployment target there is drop-down with 6.0,6.1,7.0,7.1 and 8.0

enter image description here

enter image description here

So i think yes swift support lower version.

I just test the demo that created in Xcode6 with swift language select. then i open this project in to Xcode5 with deployment target 6 and that runs it means that working with lower version too.

Here it is a screenshot of swift project runs in xcode5 with ios6.1 simulator:

enter image description here

HERE IT IS DEMO AS WELL http://www.filedropper.com/demo_5

Nitin Gohel
  • 49,482
  • 17
  • 105
  • 144
  • 1
    Actually [it doesn't](http://stackoverflow.com/questions/24001778/do-swift-based-apps-work-on-os-x-10-9-ios-7-and-lower?rq=1). Just because the option is there doesn't mean it will compile. – 67cherries Jun 04 '14 at 13:05
  • i just test the demo that created in Xcode6 with swift language select. then i open this project in to Xcode5 with deployment target 6 and that runs it means that working. – Nitin Gohel Jun 04 '14 at 13:06
  • Have you tried to run it with a deployment target of 6.0? – 67cherries Jun 04 '14 at 13:08
  • @NitinGohel So does it means that we should use the xcode 6 and we will be able to code for the apps with deployment target less than ios 7 or 8 ? – iShwar Jun 04 '14 at 13:19
  • i just got option in xcode6 that appear till ios6 in deployment drop Down. if swift not allow less then ios7 then why does that drop down appear. – Nitin Gohel Jun 04 '14 at 13:20
  • @NitinGohel thank you for your time and explanation, and we will wait for some authorised statement to make it sure. – iShwar Jun 04 '14 at 13:28
2

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.

Rajashree
  • 21
  • 2
0

No, only iOS 7+ and OS X 10.9+.

Oleksandr Skrypnyk
  • 2,762
  • 1
  • 20
  • 25
0

You can import and run swift code from Objective-C like this:

#import “ProductModuleName-Swift.h”

MySwiftClass *swiftObject = [[MySwiftClass alloc] init];
[swiftObject swiftMethod];

You can check the iOS version number with this gist and only run the swift code if the version is >= 7.0.

67cherries
  • 6,931
  • 7
  • 35
  • 51
0

Yes, the minimum deployment target for Xcode 6 with Swift language is iOS 6.0

Audrey Sobgou Zebaze
  • 2,840
  • 2
  • 19
  • 9
-1

Yes you can. Its not important in which language you are writing the code. Finally what matters is compiler and architecture. So, you should definitely able to deploy them to OS version less than 7.0

Apurv
  • 17,116
  • 8
  • 51
  • 67