将自定义方法添加到单独文件中的 Core Data 托管对象的方法是什么?

发布于 2024-11-02 23:09:47 字数 363 浏览 1 评论 0原文

将自定义方法添加到单独文件中的 Core Data 托管对象的方法是什么?我猜想特别是要求:

  1. 不想接触 XCode4 生成的类(即可以随时重新生成它们,而不必在其中重做更改)
  2. 可以有效地将方法添加到生成的类(假设类名不存在)不会改变)

注意 - 我知道 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:

  1. don't want to touch the XCode4 generated classes (i.e. so can regenerator them anytime and not have to redo changes within them)
  2. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

箹锭⒈辈孓 2024-11-09 23:09:47

修复 mogenerator 将是最好的答案:-)。

mogenerator 使用子类,因此您始终可以这样做,但类别也可以。

Fixing mogenerator would be the best answer :-).

mogenerator uses subclasses, so you could always do that, but categories would work as well.

找回味觉 2024-11-09 23:09:47

我刚刚尝试过...您对简单的#include“included_dataStuff”并将所有额外代码放入“included_dataStuff”文件有何看法。

有两种可能性:

  1. 创建一个新的ClassFile,删除包含“header.h”,(删除header.h),将额外的代码放在那里。它编译但带来两个警告:(这是可以理解的)
    [WARN]警告:没有规则可以处理架构armv6的文本类型文件“$(PROJECT_DIR)/Classes/../included_dataStuff”
    [警告]警告:没有规则来处理架构armv7的文本类型文件'$(PROJECT_DIR)/Classes/../included_dataStuff'

  2. 创建一个新的“空”文件并将额外的代码放在那里。这不会产生任何警告。

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:

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

  2. 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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文