无法在iOS上创建受管对象上下文 [英] Cannot create a managed object context on iOS

查看:120
本文介绍了无法在iOS上创建受管对象上下文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个非核心数据项目。我现在想使用核心数据。在构建阶段,我将我的二进制文件与CoreData.framework链接。在我的应用程序委托方法,我想手动创建一个托管对象上下文,像这样

  NSManagedObjectContext * aContext = [[NSManagedObjectContext alloc]在里面]; 

当我执行上述操作时,会收到以下错误:

 类消息的Receiver'NSManagedObjectContext'是一个forward声明。对于我可能做错了什么建议?

=h2_lin>解决方案

您需要在应用程序委托的头文件中导入CoreData / CoreData.h:

  #import< CoreData / CoreData.h> 

因为你可能通过outyour应用程序使用它,你应该把它放在预编译的头文件中,YourApp-Prefix .pch:

  #ifdef __OBJC__ 
#import< UIKit / UIKit.h>
#import< Foundation / Foundation.h>
#import< CoreData / CoreData.h>
#endif


I created a non core data project. I now want to use core data. In the build phases, I linked my binary with CoreData.framework. In my application delegate method, I want to manually create a managed object context like so

NSManagedObjectContext *aContext = [[NSManagedObjectContext alloc] init];

When I do the above, I get the following error,

Receiver 'NSManagedObjectContext' for class message is a forward declaration.

Any suggestions on what I might be doing wrong?

解决方案

You need to import CoreData/CoreData.h in your application delegate's header file:

#import <CoreData/CoreData.h>

Since you probably use it through outyour application you should put it in the precompiled header file, YourApp-Prefix.pch:

#ifdef __OBJC__
    #import <UIKit/UIKit.h>
    #import <Foundation/Foundation.h>
    #import <CoreData/CoreData.h>
#endif

这篇关于无法在iOS上创建受管对象上下文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆