xcode 核心数据 - 如何生成 CoreDataGeneratedAccessors?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9461659/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 23:27:02  来源:igfitidea点击:

Core Data - how to generate CoreDataGeneratedAccessors?

iphoneiosxcodecore-data

提问by Krishna

I've gone through apple dev website, google and stack overflow to figure out the basics behind CoreDataGeneratedAccessors.

我浏览了苹果开发网站、谷歌和堆栈溢出,以了解 CoreDataGeneratedAccessors 背后的基础知识。

I'm using Xcode 4.2 and core data. I created entities and their relationships properly including inverse.

我正在使用 Xcode 4.2 和核心数据。我正确地创建了实体及其关系,包括逆。

Following code is failing:

以下代码失败:

    self.remdetail = [NSEntityDescription insertNewObjectForEntityForName:@"RemDetail" inManagedObjectContext:context];
    [rem addRemDetailObject:remdetail];  --> I'm trying to add rem detail to rem object

because there are no accessor methods generated automatically, I put the following code manually in one of the NSManagedObject subclass. The following code was not generated when i created NSManagedObjects for my entities. I tried to generate accessors automatically by going through few articles and suggestions like Xcode copy & paste etc but nothing is generating the following code.

因为没有自动生成的访问器方法,我将以下代码手动放在 NSManagedObject 子类之一中。当我为我的实体创建 NSManagedObjects 时,没有生成以下代码。我试图通过阅读一些文章和建议(例如 Xcode 复制和粘贴等)来自动生成访问器,但没有生成以下代码。

in rem ManagedObject -->

在 rem ManagedObject -->

@interface Rem (CoreDataGeneratedAccessors)
- (void)addRemDetailObject:(RemDetail *)value;
- (void)removeRemDetailObject:(RemDetail *)value;
- (void)addRemDetail:(RemDetail *)value;
- (void)removeRemDetail:(RemDetail *)value;
@end

does anyone know how to generate CoreDataGeneratedAccessors?

有谁知道如何生成 CoreDataGeneratedAccessors?

Thanks, Rama

谢谢,拉玛

回答by Julien

Have you checked the switch "To-Many Relationship" in the relationship properties?

您是否检查了关系属性中的“对多关系”开关?

回答by Cloud9999Strife

@Julien's answer was part of the solution, but here is how I solved it:

@Julien 的回答是解决方案的一部分,但我是这样解决的:

  1. Make sure that you have a to-many relationship.
  2. If you already made a class for your entity, delete it, then with your xcdatamodel open, go to Editor -> create NSManagedObject subclass, and follow the wizard.
  1. 确保您有一对多的关系。
  2. 如果你已经为你的实体创建了一个类,删除它,然后打开你的 xcdatamodel,转到 Editor -> create NSManagedObject subclass,然后按照向导操作。

The class that is generated will have CoreDataGeneratedAccessorsthat you are looking for.

生成的类将具有CoreDataGeneratedAccessors您正在寻找的类。

回答by TheEye

Have a look here:

看看这里:

https://github.com/rentzsch/mogenerator

https://github.com/rentzsch/mogenerator

This little tool will generate the accessor classes for you - I use it in quite some projects and it works great!

这个小工具将为您生成访问器类 - 我在很多项目中使用它并且效果很好!

回答by Binoy jose

1)created a new version of the Core Data Model via Xcode.

1)通过Xcode创建了一个新版本的核心数据模型。

2)Fix the relationship (added a new relationship between the two.https://developer.apple.com/library/watchos/documentation/Cocoa/Conceptual/CoreData/HowManagedObjectsarerelated.html)

2)修复关系(新增了两者之间的关系。https://developer.apple.com/library/watchos/documentation/Cocoa/Conceptual/CoreData/HowManagedObjectsarerelated.html)

3)re-created the NSManagedObject subclass

3) 重新创建了 NSManagedObject 子类