崩溃 "Could not cast value of type 'LLAppDelegateProxy' "

Getting crash "Could not cast value of type 'LLAppDelegateProxy' "

我的 AppDelegate 文件中有一个方法。我是从另一个 class 打来的。但是在实施 Localytics 之后,我遇到了崩溃。这是我调用该方法的方式。

 let delegate = UIApplicatin.shared.delegate as ! AppDelegate
 delegate.myFunction()

我试过了this answer from Stack Overflow。它不会使应用程序崩溃,但不会调用方法。

成功了。实际上我漏掉了 didFinishLauncihingWithOptions 中的那一行,正如 This answer 中提到的那样。我们必须这样做。

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        AppDelegate.originalAppDelegate = self
    }