基于swift的应用程序能在OS X 10.9 (Mavericks)/iOS 7及更低版本上运行吗?

例如,我有一台运行OS X 10.8 (Mountain Lion)的机器,我想知道我用Swift写的应用程序是否能在它上面运行。

或者我应该有什么创建一个Swift应用程序使用Mac OS?


当前回答

Swift应用程序似乎不能在OS X 10.7上运行。我刚刚创建了一个简单的GUI应用程序(一个视图、一个标签、一个按钮),它在Mavericks上运行良好。基本SDK设置为10.9,部署目标设置为10.7。我把这个应用程序从DerivedData文件夹复制到我的10.7虚拟机,它在启动时崩溃了,显示这个错误:

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
...

然而,这个消息是令人恼火的,因为在这个VM中肯定有一个CoreGraphics库。其他大量使用CoreGraphics的应用程序也可以正常工作。

其他回答

这里似乎有很多旧的答案,所以我只是想发布Swift团队的官方回应。Swift向后兼容OS X Mavericks和iOS 7

苹果开发者swift博客:Objective-C id为swift Any

2014年7月11日

兼容性

我们在WWDC上听到的最常见的问题之一是,“Swift的兼容性故事是什么?”这似乎是一个很好的第一个话题。

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.

虽然代码证实了这一点,但苹果自己在WWDC 2014的技术主题演讲(平台状态,102次会议,大约34分00秒)中表示,Swift将在iOS 7和Mavericks上兼容。

苹果公司宣布Swift应用程序将向后兼容iOS 7和OS X Mavericks。WWDC应用程序是用Swift编写的。

说到Swift框架。 截至目前,在Xcode 6.1.1 (6A2008a)版本中,如果Swift框架针对iOS 7.1,链接器报告警告

ld: warning: embedded dylibs/frameworks only run on iOS 8 or later.

并且应用程序无法提交到AppStore。检查这个问题:Lint阻止动态库和框架在iOS 7中传递

Swift应用程序似乎不能在OS X 10.7上运行。我刚刚创建了一个简单的GUI应用程序(一个视图、一个标签、一个按钮),它在Mavericks上运行良好。基本SDK设置为10.9,部署目标设置为10.7。我把这个应用程序从DerivedData文件夹复制到我的10.7虚拟机,它在启动时崩溃了,显示这个错误:

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
...

然而,这个消息是令人恼火的,因为在这个VM中肯定有一个CoreGraphics库。其他大量使用CoreGraphics的应用程序也可以正常工作。