“额外”应该放在哪里?执行?

发布于 2024-09-24 07:56:18 字数 231 浏览 0 评论 0原文

有时,我会看到为对象创建新方法的代码片段,如下所示:

@implementation UIImage (Extras)

- (void)aMethod:(id)anObject {
  // some functionality
}

@end

我将该代码放在哪里?我是否将其放在我当前正在为其编写代码的类中?如果是这样,我需要将其放在代码中的什么位置?

谢谢。

Occationaly I see snippets of code creating new methods for objects and such that looks like this:

@implementation UIImage (Extras)

- (void)aMethod:(id)anObject {
  // some functionality
}

@end

Where do I put this code? Do I put it in the class I'm currently writing code for? If so at what point in the code do I need to put this?

Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

眼眸 2024-10-01 07:56:18

您可以将此类别代码放在您喜欢的任何位置。一般来说,此代码应位于名为 UIImage+Extras.m 的文件和匹配的头文件 UIImage+Extras.h 中。

You can put this category code whereever you like. In general, this code should be in a file called UIImage+Extras.m and a matching header file UIImage+Extras.h.

天邊彩虹 2024-10-01 07:56:18

为了简单起见并保持代码整洁,我通常将类类别放在单独的文件中。

但总的来说,我认为您只需要在某个标头中声明您的类别并导入它即可让编译器知道您添加的方法。这些方法的实现可以放在任何(实现)文件中,但我再次认为最好将其保存在单独的位置。

For the sake of simplicity and to keep code clean I usually put class categories in separate files.

But in general I think you just need to declare your category in some header and import it to let compiler know about methods you add. Implementation of those methods can be put in any (implementation) file, but once again I think it is better to keep it in separate place.

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