AppDelegate valueForUndefinedKey

时间:2018-04-02 11:08:43

标签: ios swift service delegates appdelegate

我正在快速制作应用程序,但我遇到了一些问题。我正在尝试运行我的应用程序,但每次都会出错。

这是完整的错误:  ***由于未捕获的异常终止应用程序' NSUnknownKeyException',原因:' [valueForUndefinedKey:]:此类不是键值currentUnityController的键值编码兼容。'

在AppDelegate中,我使用这样的服务:

@UIApplicationMain
final class AppDelegate: AppwiseCore.AppDelegate<Config> {
override var services: [ApplicationService] {
    return [
        UnityApplicationService(),
        FabricApplicationService(),
        KeyboardManagerApplicationService()
    ]
}
}

然后我像这样调用UnityAppcontroller:

var window: UIWindow?

var application: UIApplication?
@objc var currentUnityController: UnityAppController!
var isUnityRunning = false

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    // Override point for customization after application launch.
    self.application = application
    unity_init(CommandLine.argc, CommandLine.unsafeArgv)
    currentUnityController = UnityAppController()
    currentUnityController.application(application, didFinishLaunchingWithOptions: launchOptions)

    startUnity()
    return true
}

最后这就是我访问app控制器的方式。

NS_INLINE UnityAppController* GetAppController()
{
NSObject<UIApplicationDelegate>* delegate = [UIApplication sharedApplication].delegate;
UnityAppController* currentUnityController = (UnityAppController*)[delegate valueForKey: @"currentUnityController"];
return currentUnityController;

}

Anny帮助?

1 个答案:

答案 0 :(得分:0)

如果您的nib(xib文件)中有一个控件链接到视图控制器中的属性(IBOutlet)或方法(IBAction),并且您已删除或重命名了该属性或方法,则运行时可以&# 39;找不到它,因为它已被重命名,因此崩溃。