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

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

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


当前回答

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

其他回答

试试下面的代码:

它在没有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
}

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

我刚刚为你测试了一下,Swift应用程序编译成标准二进制文件,可以在OS X 10.9和iOS 7上运行。


简单的Swift应用程序用于测试:

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
}

是的,事实上苹果已经宣布Swift应用程序将向后兼容iOS 7和OS X Mavericks。此外,WWDC应用程序是用Swift编程语言编写的。

我读了所有回答:不,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。

这是模拟器的截图:

这里还有一个演示