基于swift的应用程序能在OS X 10.9 (Mavericks)/iOS 7及更低版本上运行吗?
例如,我有一台运行OS X 10.8 (Mountain Lion)的机器,我想知道我用Swift写的应用程序是否能在它上面运行。
或者我应该有什么创建一个Swift应用程序使用Mac OS?
基于swift的应用程序能在OS X 10.9 (Mavericks)/iOS 7及更低版本上运行吗?
例如,我有一台运行OS X 10.8 (Mountain Lion)的机器,我想知道我用Swift写的应用程序是否能在它上面运行。
或者我应该有什么创建一个Swift应用程序使用Mac OS?
当前回答
Swift代码可以部署在OS X 10.9和iOS 7.0上。在较旧的操作系统版本上,它通常会在启动时崩溃。
其他回答
说到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不能在iOS 7以下的系统上运行。但我说是的,我刚刚创建了一个Swift项目,它在Xcode 5 6.0部署目标中运行。
我只是用选择的Swift编程语言在Xcode 6 BETA中创建了一个演示项目。 关闭Xcode 6 beta,我在Xcode 5中以部署目标6.0打开这个演示项目 并选择模拟器6.1。
然后该项目在模拟器6.1中运行良好。我的MacOS X是10.9.3,所以我说是的,它运行在低于iOS 7的系统上。10.9.3 Mac OS X。
这是模拟器的截图:
这里还有一个演示
简而言之:
基于Swift的应用程序可以针对OS X Mavericks或iOS 7的同一应用程序。
这怎么可能?
Xcode在你的应用程序包中嵌入了一个小的Swift运行时库。因为这个库是嵌入式的,所以你的应用程序使用了一个一致的Swift版本,可以在过去、现在和未来的操作系统版本上运行。
我为什么要相信这个答案?
因为我不是像一个苹果人在推特上告诉我的那样说这个答案,或者我写了hello world并测试了它。
我从苹果开发者博客上截取的。
所以你可以相信这个。
这里似乎有很多旧的答案,所以我只是想发布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.
试试下面的代码:
它在没有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
}