将自定义方法添加到单独文件中的 Core Data 托管对象的方法是什么?
将自定义方法添加到单独文件中的 Core Data 托管对象的方法是什么?我猜想特别是要求:
- 不想接触 XCode4 生成的类(即可以随时重新生成它们,而不必在其中重做更改)
- 可以有效地将方法添加到生成的类(假设类名不存在)不会改变)
注意 - 我知道 mogenerator,但目前我对它并不满意,注意到 https://github.com/rentzsch/mogenerator/issues/55
简单且最佳的答案就是 Objective-C:类别吗?
what approach for adding custom methods to Core Data managed objects in separate files? In particular the requirements would be I guess:
- don't want to touch the XCode4 generated classes (i.e. so can regenerator them anytime and not have to redo changes within them)
- can effectively add methods to the generated classes (assumption is the class names don't change)
Note - I'm aware of mogenerator but I'm not happy with it entirely at the moment noting https://github.com/rentzsch/mogenerator/issues/55
Would the simple and best answer be just Objective-C: Categories?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
修复 mogenerator 将是最好的答案:-)。
mogenerator 使用子类,因此您始终可以这样做,但类别也可以。
Fixing mogenerator would be the best answer :-).
mogenerator uses subclasses, so you could always do that, but categories would work as well.
我刚刚尝试过...您对简单的#include“included_dataStuff”并将所有额外代码放入“included_dataStuff”文件有何看法。
有两种可能性:
创建一个新的ClassFile,删除包含“header.h”,(删除header.h),将额外的代码放在那里。它编译但带来两个警告:(这是可以理解的)
[WARN]警告:没有规则可以处理架构armv6的文本类型文件“$(PROJECT_DIR)/Classes/../included_dataStuff”
[警告]警告:没有规则来处理架构armv7的文本类型文件'$(PROJECT_DIR)/Classes/../included_dataStuff'
创建一个新的“空”文件并将额外的代码放在那里。这不会产生任何警告。
1 和 2 之间的区别在于,虽然代码格式保留在第一个选项中(必须接受 2 个警告),但在第二个选项中,所有代码格式都丢失了,并且被视为普通文本(但没有警告),
我想我更喜欢第一个。当然,对生成的代码文件的唯一修改是
#include
语句。你对此有何看法?
I just tried... What do you think about a simple #include "included_dataStuff" and putting all your extra code into the "included_dataStuff" file.
There are two possibilities:
create a new ClassFile, delete the include "header.h", (delete the header.h), put the extra code there. It compiles but brings the two warnings: (which are understandable)
[WARN]warning: no rule to process file '$(PROJECT_DIR)/Classes/../included_dataStuff' of type text for architecture armv6
[WARN]warning: no rule to process file '$(PROJECT_DIR)/Classes/../included_dataStuff' of type text for architecture armv7
create a new "empty" file and put the extra code there. This does not produce any warnings.
The difference between 1 and 2 is that while the code formatting remains in the first alternatve (having to accept the 2 warnings) in the second all the code format is lost and its treated like normal text (but there is no warning)
I guess I would prefer the first. Of course, the only modification to the generated code file would be the
#include
statement.What do you think about that?