使用 ARC 构建 Apple Core 数据教程时出错



我一直在为核心数据叹而苦苦挣扎,所以我决定在这个Apple Core Data教程中工作。 我在教程中要求我构建到目前为止整理的项目。 所以我目前就在教程中。 当我构建项目时,我收到以下错误:

Type of property 'managedObjectContext' ('NSManagedObjectContext *') does not match type of ivar 'managedObjectContext' ('MSManagedObject *__strong')

RootViewController.m

Ivar is declared here

这就是我在错误窗口中得到的。

这是我的文件的样子,

RootViewController.h http://pastie.org/4111206

RootViewController.m http://pastie.org/4111216

AppDelegate.h http://pastie.org/4111222

AppDelegate.m http://pastie.org/4111227

您的 ivar 声明不正确。 在 RootViewController.h 中,

NSManagedObject *managedObjectContext;

应该写,因为错误抱怨,

NSManagedObjectContext *managedObjectContext;

实际上,在现代运行时中,在相当长的一段时间内,没有必要(通常是不明智的)明确声明@synthesize属性的支持 ivar。 因此,您可以完全删除 ivar 行,让编译器为您制作 ivar。

错误消息已经解释了它。你有一个 ivar managedObjectContext 的类 NSManagedObject(这是你的错误)。

编译器无法合成属性 managedObjectContext,因为您具有同名但类不同的 ivar。

重命名 ivar 并更改合成行:

@synthesize managedObjectContext = _managedObjectContext;

最新更新