问题AppDelegate与新的Swift 2.2 / Xcode 7.3.1

时间:2016-06-12 14:46:35

标签: ios xcode swift appdelegate xcode7.3

我最近升级了Xcode并尝试继续编程。我的应用无法构建。它说问题出在AppDelegate中。 我复制了我的代码:

import UIKit


@UIApplicationMain
AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        // Override point for customization after application launch.

        let storyboard = UIStoryboard(name: "Main", bundle: NSBundle.mainBundle())
        let defaults = NSUserDefaults.standardUserDefaults()

        var rootViewController : UIViewController;

        if (defaults.boolForKey("HasBeenLaunched")) {
            // This gets executed if the app has ALREADY been launched
            rootViewController = storyboard.instantiateViewControllerWithIdentifier("maintabcontroller") as UIViewController
        } else {
            // This gets executed if the app has NEVER been launched
            defaults.setBool(true, forKey: "HasBeenLaunched")
            defaults.synchronize()
            rootViewController = storyboard.instantiateViewControllerWithIdentifier("setupstory") as UIViewController
        }

        window?.rootViewController = rootViewController;
        window?.makeKeyAndVisible();

        UITabBar.appearance().barTintColor = UIColor.whiteColor()

        UITabBar.appearance().tintColor = UIColor.blackColor()
        return true
    }
}

错误在AppDelegate: UIResponder, UIApplicationDelegate {行中。他们是:

  • 预期声明
  • 语句不能以闭包表达式开头
  • 表达式不允许在顶级
  • 支持的语句块是未使用的
  • 表达式解析为未使用的函数

在升级之前,我没有收到所有这些错误。

1 个答案:

答案 0 :(得分:1)

您意外删除了class关键字:

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {