Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/105.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何访问UIApplication.shared.delegate as?来自NSObject的AppDelegate_Ios_Swift_Core Data - Fatal编程技术网

Ios 如何访问UIApplication.shared.delegate as?来自NSObject的AppDelegate

Ios 如何访问UIApplication.shared.delegate as?来自NSObject的AppDelegate,ios,swift,core-data,Ios,Swift,Core Data,我有一节课 final class Restaurant{... class func makeNewRestaurant{... // this makes instance of Restaurant } } 在这个类中,它是RestaurantMO(managedobject)的一个实例,我有一个类方法makeNewRestaurant,它创建了Restaurant的一个新实例 我还需要一个类方法saveNewRestaurant(Resta

我有一节课

 final class Restaurant{...

      class func makeNewRestaurant{...
         // this makes instance of Restaurant
      }
}
在这个类中,它是RestaurantMO(managedobject)的一个实例,我有一个类方法makeNewRestaurant,它创建了Restaurant的一个新实例

我还需要一个类方法saveNewRestaurant(Restaurant:aRestaurant),它将Restaurant保存到persistentcainer.viewContext(即核心数据)。当我尝试以下操作时,我得到以下错误

appDelegate = (UIApplication.shared.delegate as? AppDelegate

错误“使用未解析的标识符应用程序”。我认为餐厅不应该有权使用AppDelegate。那么,我如何从Restaurant内访问persistentContainer.viewContext,并从我的类方法saveNewRestaurant保存实例?

此文件中是否缺少一个导入UIKit?不,这是可行的,但我应该将UIKit导入NSObject吗?它不是用来显示的?@jdog类
UIApplication
是在模块UIKit中定义的(“UIApplication”中的“UI”前缀是一个很大的赠品;)。UIKit不仅仅是“显示”:它基本上管理iOS中所有特定于平台的代码;例如:响应器链、应用程序对象和(是的)视图层次结构。macOs上的模拟功能由AppKit处理。令人困惑的是,AppKIT类的名称以“NS”为前缀,与基础框架中的名称相同。当苹果开发iPhone操作系统时,他们明智地为UI框架(UIKit)中的类选择了一个单独的前缀。我相信基金会在两个平台上都是一样的。