重写insertInManagedObjectContext:将不会影响子实体在mogenerator:为什么和如何做? [英] Overriding insertInManagedObjectContext: will have no effects on child entities in mogenerator : why and how to do?

查看:202
本文介绍了重写insertInManagedObjectContext:将不会影响子实体在mogenerator:为什么和如何做?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在由 mogenerator 提供的 insertInManagedObjectContext:方法中,不会调用任何超级方法。

In the methods insertInManagedObjectContext: provided by mogenerator, there is no call to any super methods.

我不知道为什么。

确实,


  • 想象我有两个实体: ParentEntity ChildEntity ;当然, ParentEntity ChildEntity 的父实体。

  • 我覆盖 ParentEntity insertInManagedObjectContext:

  • 但是,当我创建 ChildEntity 时,我的更改不会记入帐户!

  • Imagine I have two entities : ParentEntity and ChildEntity ; of course, ParentEntity is the parent entity of ChildEntity.
  • Then, I override the insertInManagedObjectContext: of the ParentEntity.
  • But then, when I create a ChildEntity, none of my changes will be taken in account !!

我想知道为什么要这样的选择,也许是解决方案。

I was wondering why such a choice and maybe a solution.

我的需要是创建一个带孩子的超级实体,这个超级实体有两个插入方法。我想这两个插入方法可以被孩子们使用。

My need is to create a super entity with children and that this super entity have two insert methods. I want these two insert methods to be usable by the children.

推荐答案

可能他们没有以同样的方式想

Probably they just didn't think of it the same way you do.

至于你能做什么,为什么不实现自己的方法代替 insertInManagedObjectContext:并且调用super的实现?生成文件,然后将您的新方法放在 ChildEntity.m 中,并将该版本调用super的版本。您不能使用相同的方法名称,因为 _ChildEntity.m 将有一个不调用super的版本。所以,使用一些其他方法名称。

As for what you can do, why not implement your own method to take the place of insertInManagedObjectContext: and have it call super's implementation? Generate the files, then put your new method in ChildEntity.m, and have that version call super's version. You can't use the same method name since _ChildEntity.m will have one that doesn't call super's version. So, use some other method name.

这篇关于重写insertInManagedObjectContext:将不会影响子实体在mogenerator:为什么和如何做?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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