• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

是否可以在 Objective-C 创建自定义指令?

用户头像
it1352
帮助1

问题说明

Objective-C 有如下指令:

Objective-C has directives like:

  • @interface
  • @实现
  • @end
  • @protocol
  • @property
  • @synthesize

我想到了诸如复杂的 marco 或代码生成器之类的东西.是否可以为代码生成目的创建自定义指令?一种可能的用途是为 CoreData 生成方法.

I think of these things like sophisticated marco or code-generators. Is it possible to create custom directives for code-generation purposes? One possible use is generating methods for CoreData.

我不这么认为,因为我从未见过它,但我的世界不是世界.

I'm thinking not, because I've never seen anything about it, but my world isn't the world.

后续问题:

Jonathan 在下面提到可以编写自己的预处理器,这引出了如何做的问题.目前,#define SYMBOLIC_CONSTANT 102 将在文件移动到编译器之前用文件中的字符 102 替换字符 SYMBOLIC_CONSTANT 的所有实例.

Jonathan mentioned below that it is possible to write your own preprocessor and this begs the question of how. Currently, #define SYMBOLIC_CONSTANT 102 will replace all instances of the characters SYMBOLIC_CONSTANT with the characters 102 in the file before the files moves on to the compiler.

我知道 XCode 您可以向 Targets 构建过程添加运行脚本阶段".因此,我可以编写一个脚本来查找我的自定义预处理指令,例如$coredata",然后让脚本生成一个新文件,该文件将 $coredata 字符替换为某些代码字符.但是根据我对 XCode 构建过程的理解,您无法将更改的文件提供给编译器源阶段.文件由 IDE 指定并锁定.

I know it XCode you can add a "Run Script Phase" to a Targets build process. So I could write a script to find my custom preprocess directives like '$coredata' and then have the script generate a new file that with the characters $coredata replaced with some characters of code. But from what I understand of XCode's build process you can't feed altered files into the Compiler Sources phase. The files are specified and locked by the IDE.

有没有人做过类似的事情?我知道使用外部构建系统是可能的,但老实说,我没有达到那种理解水平.我不知道构建和运行"按钮的技术细节.

Has anyone done something similar? I know it's possible with external build system, but to be honest I'm not at that level of understanding. I don't know the technical details of what the Build and Run button does.

与此同时,我将开始阅读 Apple 的 XCode 文档...

In the meantime, I'll start reading Apple's XCode Documentation...

感谢您的回复!

正确答案

#1

您的想法是正确的:在您的代码中不可能做到这一点.添加更多 @ 指令的唯一方法是通过编译器本身.即使您遇到了所有这些麻烦,我几乎可以保证对它们的语法高亮支持已硬编码到某个 Xcode 配置文件中.

Your thinking is correct: it is impossible to do this in your code. The only way to add more @-directives is via the compiler itself. Even if you went to all that trouble, I can almost guarantee that the syntax highlighting support for them is hard-coded into an Xcode configuration file somewhere.

哦,如果您正在考虑使用预处理器宏,我的理解是 @ 字符在预处理器宏中是非法的.

Oh, and if you were considering the use a pre-processor macro, it is my understanding that the @ character is illegal in pre-processor macros.

我进行了测试,我是正确的.在 C 预处理器宏中使用 @ 字符是非法的.它们遵循与变量名称相同的规则.

I ran a test, and I am correct. Using the @ character in a C preprocessor macro is illegal. They follow the same rule as variable names.

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /reply/detail/tanhcgabfb
系列文章
更多 icon
同类精品
更多 icon
继续加载