基于 swift 的应用程序能在 OS x 10.9 / ios7和更低的版本上运行吗?

Will Swift-based applications work on OS X 10.9 (Mavericks)/iOS 7 and lower?

For example, I have a machine running OS X 10.8 (Mountain Lion), and I am wondering if an application I write in Swift will run on it.

转载于:https://stackoverflow.com/questions/24001778/do-swift-based-applications-work-on-os-x-10-9-ios-7-and-lower

csdnceshi59
ℙℕℤℝ This question is the one that's used as an example on the tour page.
3 年多之前 回复
weixin_41568183
零零乙 Swift 2.0 update: iOS 7 / 10.9 just like Swift 1.0. [Per my answer here.][1] [1]: stackoverflow.com/a/31702716/201199
大约 5 年之前 回复
weixin_41568208
北城已荒凉 No need to worry about... Apple: 80 percent of active users are now running iOS 7 - arstechnica.com/apple/2014/01/…
大约 6 年之前 回复
csdnceshi79
python小菜 In Xcode 6 beta 3, Swift compiler no longer accepts any deprecated APIs in 10.9 and lower, which makes it even harder to back port current code to work with older OS versions.
6 年多之前 回复
csdnceshi74
7*4 It is public knowledge and was even mentioned in the keynote that it runs on those operating systems.
6 年多之前 回复
csdnceshi66
必承其重 | 欲带皇冠 FWIW: at the WWDC, in the Swift presentation it was most clearly stated that Swift and Objective-C have the same runtime.
6 年多之前 回复
weixin_41568134
MAO-EYE An official answer will be found in the State of the Union video.
6 年多之前 回复
csdnceshi80
胖鸭 Assuming Swift is compiled into a "normal" executable and assuming there is no Swift specific runtime library needed in the OS, then yes, it should run on older systems. We just don't know yet. Download Xcode 6 and try it.
6 年多之前 回复

18个回答

I just tested it for you, Swift applications compile into standard binaries and can be run on OS X 10.9 and iOS 7.


Simple Swift application used for testing:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool {
    self.window = UIWindow(frame: UIScreen.mainScreen().bounds)

    var controller = UIViewController()
    var view = UIView(frame: CGRectMake(0, 0, 320, 568))
    view.backgroundColor = UIColor.redColor()
    controller.view = view

    var label = UILabel(frame: CGRectMake(0, 0, 200, 21))
    label.center = CGPointMake(160, 284)
    label.textAlignment = NSTextAlignment.Center
    label.text = "I'am a test label"
    controller.view.addSubview(label)

    self.window!.rootViewController = controller
    self.window!.makeKeyAndVisible()
    return true
}
csdnceshi52
妄徒之命 If your project contains a custom Cocoa Framework, Swift will not work with iOS7.
接近 6 年之前 回复
csdnceshi74
7*4 Xcode noticed me 'iPhone 5 (7.0.3) is not available' when I run my swift project. But 7.1 OK.
大约 6 年之前 回复
weixin_41568174
from.. In Xcode 6 GM if you select iOS 6 as a deployment target it will not compile, and gives the following error message: "Swift I sun available on iOS earlier than 7.0; please set IPHONEIOS_DEPLOYMENT_TARGET to 7.0 or later.
大约 6 年之前 回复
csdnceshi60
℡Wang Yan For iOS : in Xcode 6 beta, there are deployment targets up to iOS 6. I tested them all out, worked find. There are some answers stuating the same.
6 年多之前 回复
csdnceshi57
perhaps? I would suggest keeping with the spirit of Swift and removing the explicit type declaration on controller and label, e.g. var controller = UIViewController(). One of the major principals of Swift seems to be about removing "noise".
6 年多之前 回复
csdnceshi79
python小菜 I don't have any Swift experience, but I suppose the first UIViewController after the colon represents the type of the variable and the second occurrence after the = sign calls the constructor (initializes the variable).
6 年多之前 回复
csdnceshi56
lrony* By using var keyword, why do we need to type UIViewController two times in this line "var controller: UIViewController = UIViewController()"? Is var not same as JavaScript/C# (if no, then so sad)? Is this casting, but object types are same on both sides of equal sign?
6 年多之前 回复
csdnceshi71
Memor.の I've only tested iOS 7.0 and OS X 10.9. As said in the answer.
6 年多之前 回复
weixin_41568126
乱世@小熊 See stackoverflow.com/questions/24007050/… - it conflicts with this answer (at least the "or even lower" part).
6 年多之前 回复

Swift code can be deployed to OS X 10.9 and iOS 7.0. It will usually crash at launch on older OS versions.

csdnceshi71
Memor.の The minimum supported deployment targets for Swift-built executables remain iOS 7.0 and OSX 10.9. APIs deprecated in iOS 7/OSX 10.9 or earlier will be unavailable. When building, Swift only supports the SDK it ships with in Xcode.
5 年多之前 回复
csdnceshi60
℡Wang Yan Any chance you can update this answer for Swift 2, whether the runtime requirements have changed or not?
5 年多之前 回复
csdnceshi52
妄徒之命 I'd MUCH appreciate if Apple would consider making Swift apps work on older platforms too (at least from OSX 10.7 onwards). Reason is that we still have many customers with this OS, so we cannot start developing with Swift for years if 10.9 is the minimum supported OS!
6 年多之前 回复
csdnceshi72
谁还没个明天 Swift sets some bits in the Objective-C metadata to mark Swift classes. libobjc in OS X 10.9 and iOS 7.0 was changed to ignore these bits in preparation for Swift's arrival. Older OS versions will be confused by these bits.
6 年多之前 回复
csdnceshi54
hurriedly% Greg, thanks for coming here to answer questions. Can you say a bit about what changed 10.8->10.9 and 6.x->7.0 that allows code generated from Swift to run?
6 年多之前 回复
csdnceshi56
lrony* That's as definitive as it gets. Mr. Parker is in the guts of it.
6 年多之前 回复

Apple has announced that Swift apps will be backward compatible with iOS 7 and OS X Mavericks. The WWDC app is written in Swift.

csdnceshi73
喵-见缝插针 Yes. I did not dispute that. I was, however, reacting to multiple statements saying the WWDC app was written in Swift without the qualifier "partially".
6 年多之前 回复
csdnceshi55
~Onlooker but 4 classes are enough to answer the compatibility question.
6 年多之前 回复
weixin_41568174
from.. Has anyone said yet that Swift apps won't be backward compatible with devices below iOS 7 and Mavericks?
6 年多之前 回复
csdnceshi64
游.程 Maybe it was written in swift, but they released a different version to the public..
6 年多之前 回复
csdnceshi68
local-host Apple's marketing tactic is a common one used by businesses though. Windows was written in Assembly! Well, only the bootloader and some other things, but it was written in assembly.
6 年多之前 回复
csdnceshi73
喵-见缝插针 Jay Freeman claims otherwise: twitter.com/saurik/status/473785847926374400
6 年多之前 回复
csdnceshi50
三生石@ Yes, WWDCC app is written in Swift. As they said yesterday.
6 年多之前 回复
csdnceshi62
csdnceshi62 Really WWDC is written in Swift??
6 年多之前 回复

This is the post I read from apple Swift blog, might be helpful:

App Compatibility:

If you write a Swift app 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.

Binary Compatibility and Frameworks:

While your app's runtime compatibility is ensured, the Swift language itself will continue to evolve, and the binary interface will also change. To be safe, all components of your app should be built with the same version of Xcode and the Swift compiler to ensure that they work together.

This means that frameworks need to be managed carefully. For instance, if your project uses frameworks to share code with an embedded extension, you will want to build the frameworks, app, and extensions together. It would be dangerous to rely upon binary frameworks that use Swift — especially from third parties. 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 applications are supported on iOS 7 and above as stated in Beta 4 release notes. iOS 6.0, 6.1, 7.0, 7.1, 8.0 in Xcode 6 Beta

Swift applications are supported on platforms OS X 10.9 and above. OS X 10.4 to 10.10 in Deployment Target. I have tested on targeting 10.5 to 10.10, and running on 10.9.3

weixin_41568134
MAO-EYE I also saw it and tested all the deployment target in Xcode 6 beta (same as the answer). Worked fine using 2 different test apps.
6 年多之前 回复
csdnceshi75
衫裤跑路 no, I did text only on OS X (0.7).
6 年多之前 回复
csdnceshi50
三生石@ Lischke, did you test iOS apps on devices?
6 年多之前 回复
csdnceshi75
衫裤跑路 How do you explain my results then? And what about what Greg Parker wrote? I'd be very happy if Swift Apps would work on 10.7 but so far I haven's seen a working example. Of course I can set 10.7 as deployment target too, but it doesn't make a difference. The app crahs.
6 年多之前 回复
csdnceshi50
三生石@ Lischke, again, I had several tests to back up my arguments. And I can run OS X app when I select Deployment Target 10.7. But I do appreciate that you brought up the thread of OS X app supports.
6 年多之前 回复
csdnceshi75
衫裤跑路 I think the various deployment targets are just not yet correct (XCode 6 is a beta). Just because you can select the value doesn't mean it works. I tried with OSX 10.7 as target and it did not work. Also note that an authorative confirmation about platforms has been given above by Greg Parker.
6 年多之前 回复

It appears Swift applications don't run on OS X 10.7. I just created a simple GUI application (a view, a lable, a button) which runs fine on Mavericks. The base SDK is set to 10.9 and the deployment target to 10.7. I copied that application from the DerivedData folder over to my 10.7 virtual machine, and it crashs when starting, show this error:

Crashed Thread:  0

Exception Type:  EXC_BREAKPOINT (SIGTRAP)
Exception Codes: 0x0000000000000002, 0x0000000000000000

Application Specific Information:
dyld: launch, loading dependent libraries

    Dyld Error Message:

  Library not loaded: /System/Library/Frameworks/CoreGraphics.framework/Versions/A/CoreGraphics
  Referenced from: /Users/USER/Desktop/Swift-Test.app/Contents/MacOS/../Frameworks/libswiftAppKit.dylib
  Reason: image not found

Binary Images:
       0x109c65000 -        0x109c6afff +private.Swift-Test (1.0 - 1) <649695D0-58FD-3D02-9176-2D40D4E711F2> /Users/USER/Desktop/Swift-Test.app/Contents/MacOS/Swift-Test
       0x109c83000 -        0x109dbffff +libswift_stdlib_core.dylib (1.0 - 600.0.34.4.5) <10AAC369-9404-321D-A892-49F65856D7AF> /Users/USER/Desktop/Swift-Test.app/Contents/Frameworks/libswift_stdlib_core.dylib
...

However this message is irritating, since there's certainly a CoreGraphics library in this VM. Other applications that make heavy use of CoreGraphics work just fine.

I read all answers that said: No, Swift does not work with less than iOS 7. But I said YES, I just created a Swift project that does run in Xcode 5 with 6.0 deployment target.

  • I just create a demo project in Xcode 6 BETA with the Swift programming language selected.
  • Close Xcode 6 beta, and I open this demo project in Xcode 5 with deployment target 6.0
  • And also select simulator 6.1.

Then that project runs well in simulator 6.1. My MacOS X is 10.9.3, so I said yes, that runs in lower than iOS 7. with 10.9.3 Mac OS X.

Here it is a screenshot of the simulator:

Enter image description here

Here is a demo as well

csdnceshi80
胖鸭 ur demo code bhai ?
4 年多之前 回复
weixin_41568184
叼花硬汉 first you try with demo code if that works then yes that definaty works
4 年多之前 回复
csdnceshi80
胖鸭 i mean i have converted an objective c app to swift and have customers who are there on ios 6 . So will the swift app work ?
4 年多之前 回复
weixin_41568184
叼花硬汉 you can see the simulatore screenshot :) i did not create above attached screenshot in photoshop
4 年多之前 回复
csdnceshi80
胖鸭 Does it really work in ios 6 ?
4 年多之前 回复
weixin_41568184
叼花硬汉 this above sample code is build in xcode5
大约 6 年之前 回复
csdnceshi77
狐狸.fox Question: Without swift support how XCode-5 builds the swift source?
大约 6 年之前 回复

Quick Update, effective from February 15th, 2015, we cannot submit apps to the store that were developed using an SDK prior to iOS 8. So, keeping that in mind , its better to not to worry about this issue as many people have suggested that apps made in Swift can be deployed to OS X 10.9 and iOS 7.0 as well.

csdnceshi79
python小菜 Current Apple documentation still mentions support for iOS 4.3: developer.apple.com/library/content/documentation/IDEs/…
3 年多之前 回复
csdnceshi79
python小菜 There is a difference between Base SDK and Deployment Target. You can have a Base SDK of iOS 9 and a Deployment Target of iOS 7 and submit to iTunes Connect. Downvoting because you did not provide a source.
3 年多之前 回复
csdnceshi74
7*4 Would you provide us a source ?
4 年多之前 回复

There seems to be a lot of old answers here so I just wanted to post the official response from the Swift team. Swift is backwards compatible with OS X Mavericks and iOS 7

Apple developer swift blog : Objective-C id as Swift Any

Jul 11, 2014

Compatibility

One of the most common questions we heard at WWDC was, “What is the compatibility story for Swift?”. This seems like a great first topic.

App Compatibility Simply put, if you write a Swift app today and submit it to the App Store this Fall when iOS 8 and OS X Yosemite are released, 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.

Try the following code:

It's working without StoryBoard:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool {
    self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
    self.window!.backgroundColor = UIColor.whiteColor()

    // Create a nav/vc pair using the custom ViewController class

    let nav = UINavigationController()
    let vc = ViewController(nibName: "ViewController", bundle: nil)

    // Push the vc onto the nav
    nav.pushViewController(vc, animated: false)

    // Set the window’s root view controller
    self.window!.rootViewController = nav

    // Present the window
    self.window!.makeKeyAndVisible()
    return true
}
csdnceshi59
ℙℕℤℝ And how to use nav.rootviewcontroller ??
6 年多之前 回复
共18条数据 1 尾页
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐