Overriding insertInManagedObjectContext: will have no effects on child entities in mogenerator : why and how to do?

非 Y 不嫁゛ 提交于 2019-12-12 05:03:17

问题


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

I wonder why.

Indeed,

  • 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.


回答1:


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

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.



来源:https://stackoverflow.com/questions/16430005/overriding-insertinmanagedobjectcontext-will-have-no-effects-on-child-entities

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!