【发布时间】:2016-03-28 20:36:49
【问题描述】:
在 iOS 应用程序中,您可以通过以下方式获取对共享应用程序委托的引用:
斯威夫特:let delegate = UIApplication.sharedApplication().delegate as! AppDelegate
Objective-C:AppDelegate *delegate = [[UIApplication sharedApplication] delegate];
在 WatchKit2 App Extension 中有一个类似的 App Delegate,我想在视图控制器中获取对它的引用以访问应用程序中的共享资源,例如核心数据堆栈的 ManagedObjectModel 和 PersistentStoreCoordinator,我有在 App Delegate 中初始化。
但是UIApplication.sharedApplication().delegate as! AppDelegate报错,
使用未解析的标识符“UIApplication”
如何在 WatchKit2 应用扩展中访问应用委托?
【问题讨论】:
标签: objective-c swift watchkit uiapplicationdelegate wkextension