标签: wkextension

WatchKit 中 UIApplication.sharedApplication().delegate 的等价物是什么?

在 iOS 应用程序中,您可以通过以下方式获取对共享应用程序委托的引用:

迅速:
let delegate = UIApplication.sharedApplication().delegate as! AppDelegate

目标-C:
AppDelegate *delegate = [[UIApplication sharedApplication] delegate];

在 WatchKit2 App Extension 中有一个类似的 App Delegate,我想在视图控制器中获取对它的引用,以访问应用程序中的共享资源,例如核心数据堆栈的 ManagedObjectModel 和 PersistentStoreCoordinator,我已在应用代理。

但是,UIApplication.sharedApplication().delegate as! AppDelegate报告错误,

使用未解析的标识符“UIApplication”

如何访问 WatchKit2 应用扩展中的应用委托?

objective-c uiapplicationdelegate swift watchkit wkextension

4
推荐指数
1
解决办法
3066
查看次数