Swift App Delegate 中用于加载 Storyboard 的代码导致崩溃

Swift Code in App Delegate to Load Storyboard Causes Crash

我有一个正在编写的通用应用程序,我最初使用两个故事板文件编写它。我在 App Delegate didFinishLaunchingWithOptions 例程中有代码来决定加载哪个情节提要并离开它。从那以后我意识到这是一件愚蠢的事情,因为我有重复的代码,所以我删除了一个故事板并使另一个通用。我已将 VC 设置为指向右侧 class 和所有内容。但是,我的应用程序现在拒绝启动。当我在 sim 中 运行 它时,它给我错误

The app delegate must implement the window property if it wants to use a main storyboard file.

.

这是我在 App Delegate 中的代码:

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

    var deviceIdiom = UIDevice.currentDevice().userInterfaceIdiom
    if deviceIdiom == UIUserInterfaceIdiom.Phone {
        strDevice = "iPhone"
    } else if deviceIdiom == UIUserInterfaceIdiom.Pad {
        strDevice = "iPad"
    } else {
        strDevice = "Unknown"
    }

    return true
}

我做错了什么?

(我已经看过但没有帮助的问题): Unique Issue displaying first storyboard scene in Xcode
The app delegate must implement the window property if it wants to use a main storyboard file
Managing two storyboards in App Delegate
How to manually set which storyboard view to show in app delegate
Swift - Load storyboard programatically

您的应用委托需要像这样启动:

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

  var window: UIWindow?

  //...
}