xcode 你能在 Objective-C 中添加自定义编译器警告吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6219914/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 21:11:26  来源:igfitidea点击:

Can you add custom compiler warnings in Objective-C?

objective-cxcodecompiler-constructioncompiler-warnings

提问by zekel

(I found the answer to this elsewhere while writing the question, but I thought it might be helpful to others if I posted it since I couldn't find anything here.)

(我在写问题时在别处找到了这个答案,但我认为如果我发布它可能对其他人有帮助,因为我在这里找不到任何东西。)

I want to mark methods that need better error handling. I'd like them to show up as compiler warnings so other developers (who may be responsible for that area) will notice, and hopefully fix at their leisure.

我想标记需要更好的错误处理的方法。我希望它们显示为编译器警告,以便其他开发人员(可能负责该区域的人员)会注意到,并希望在闲暇时进行修复。

(Other approaches welcome, I looked at __attribute__((warning))but couldn't get it to work.)

(欢迎使用其他方法,我查看了 __attribute__((warning))但无法使其正常工作。)

回答by zekel

It's very easy to do:

这很容易做到:

#warning Needs better error handling, please.

回答by Abhishek Bedi

Select your target and then select the Build Phases tab. At the bottom of the window you'll see an option to Add Build Phase at the bottom of the screen. You can use the Add Build Phase to add a Run Script build phase. The Run Script option allows you to select a shell and execute arbitrary code against the project.

选择您的目标,然后选择 Build Phases 选项卡。在窗口底部,您将在屏幕底部看到添加构建阶段的选项。您可以使用添加构建阶段来添加运行脚本构建阶段。Run Script 选项允许您选择一个 shell 并针对项目执行任意代码。

To warn about TODO & FIXMEcomments, use /bin/sh as the shell and paste in this script:

要警告TODO 和 FIXME注释,请使用 /bin/sh 作为 shell 并粘贴到此脚本中:

TAGS="TODO:|FIXME:"
echo "searching ${SRCROOT} for ${TAGS}"
find "${SRCROOT}" \( -name "*.h" -or -name "*.m" \) -print0 | xargs -0 egrep --with-filename --line-number --only-matching "($TAGS).*$" | perl -p -e "s/($TAGS)/ warning: $1/"

Source : Generate Xcode Warnings from TODO Comments

来源:从 TODO 注释生成 Xcode 警告