【问题标题】:problems AppDelegate with new Swift 2.2 / Xcode 7.3.1新的 Swift 2.2 / Xcode 7.3.1 的 AppDelegate 问题
【发布时间】:2016-06-12 14:46:34
【问题描述】:

我最近升级了 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 { 行中。它们是:

  • 预期声明
  • 语句不能以闭包表达式开头
  • 不允许在顶层使用表达式
  • 大括号语句块未使用
  • 表达式解析为未使用的函数

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

【问题讨论】:

  • 您在AppDelegate: UIResponder, UIApplicationDelegate { 之前缺少一个“class
  • 您可以创建一个新的空项目并查看您的项目中缺少什么。

标签: ios xcode swift appdelegate xcode7.3


【解决方案1】:

您不小心删除了 class 关键字:

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

【讨论】:

  • 我试过了,还是不行。我该如何解决?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-12-29
  • 2016-11-09
相关资源
最近更新 更多