是否可以在 Objective-C 创建自定义指令?
问题说明
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...
感谢您的回复!
正确答案
您的想法是正确的:在您的代码中不可能做到这一点.添加更多 @
指令的唯一方法是通过编译器本身.即使您遇到了所有这些麻烦,我几乎可以保证对它们的语法高亮支持已硬编码到某个 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
-
YouTube API 不能在 iOS (iPhone/iPad) 工作,但在桌面浏览器工作正常?
it1352 07-30 -
iPhone,一张图像叠加到另一张图像上以创建要保存的新图像?(水印)
it1352 07-17 -
保持在后台运行的 iPhone 应用程序完全可操作
it1352 07-25 -
使用 iPhone 进行移动设备管理
it1352 07-23 -
在android同时打开手电筒和前置摄像头
it1352 09-28 -
扫描 NFC 标签时是否可以启动应用程序?
it1352 08-02 -
检查邮件是否发送成功
it1352 07-25 -
Android微调工具-删除当前选择
it1352 06-20 -
希伯来语的空格句子标记化错误
it1352 06-22 -
Android App 和三星 Galaxy S4 不兼容
it1352 07-20