如何在 Xcode 中标记“待办事项”注释?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16913055/
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
How can I mark "To Do" comments in Xcode?
提问by Midhun MP
Currently I'm working on an iOS based Image Manipulation task.
目前我正在处理基于 iOS 的图像处理任务。
Problem:
问题:
I'm working on different modules. So If I need to add something in a module in future, I want to mark it as a To do note. Are there any other macros or similar to add a to do note in Xcode ?
我正在研究不同的模块。因此,如果我将来需要在模块中添加某些内容,我想将其标记为待办事项。是否还有其他宏或类似的宏可以在 Xcode 中添加待办事项?
I tried:
我试过:
For this currently I'm using #pragma
like:
为此,我目前使用的#pragma
是:
#pragma mark -
#pragma mark To do: Add the Image processing methods.
I got:
我有:
But it lists in the Method section like:
但它在方法部分列出,如:
What I actually need:
我真正需要的是:
The issue is, it's listed under the methods list so sometimes I forgot to remove this from the section also it's very difficult to find it in entire source code. (Searching #pragma results to show entire lists)
问题是,它列在方法列表下,所以有时我忘记从该部分中删除它,而且很难在整个源代码中找到它。(搜索#pragma 结果以显示整个列表)
Technical Details:
技术细节:
I'm using Xcode Version 4.6.2 .
我正在使用 Xcode 版本 4.6.2 。
回答by Midhun MP
I got it.
我知道了。
Writing comment like:
写评论如:
// TODO: Do something
Will do the trick.
会做的伎俩。
I got something like:
我得到了类似的东西:
Also there is a lot of options like:
还有很多选项,例如:
// FIXME: Midhun
// ???: Midhun
// !!!: Midhun
// MARK: Midhun
// FIXME: Midhun
// ???: Midhun
// !!!: Midhun
// MARK: Midhun
回答by Dev2rights
// TODO: the thing todo
Is how you show todo tasks.
是您显示待办事项的方式。
回答by Abizern
Using the
使用
//TODO: some thing here
works if all you want to do is to look at the list of todos in the drop down
如果您只想查看下拉列表中的待办事项列表,则可行
If you want to be intrusive you can use #warning
marks instead:
如果你想侵入你可以使用#warning
标记代替:
#warning this will create a compiler warning.
And when you build the app you will get a compiler warning (a yellow triangle, not a compiler error) which is a little more "in your face" about reminding you of things you need to do.
当您构建应用程序时,您将收到编译器警告(黄色三角形,而不是编译器错误),这更像是在提醒您需要做的事情。
回答by razor28
With the script below your can see all required tags like warnings.
使用下面的脚本,您可以看到所有必需的标签,如警告。
- Select your project in the Project Navigator
- Open the target in the sidebar and move to the "Build Phases" tab
- Click on "+" sign
- Select "New Run Script Build Phase"
Add below script to "Run Script"
The script:
KEYWORDS="TODO:|FIXME:|DevTeam:|XXX:" find "${SRCROOT}" \( -name "*.h" -or -name "*.m" -or -name "*.swift" \) -print0 | xargs -0 egrep --with-filename --line-number --only-matching "($KEYWORDS).*$" | perl -p -e "s/($KEYWORDS)/ warning: $1/"
- 在项目导航器中选择您的项目
- 在侧边栏中打开目标并移动到“构建阶段”选项卡
- 点击“+”号
- 选择“新建运行脚本构建阶段”
将下面的脚本添加到“运行脚本”中
脚本:
KEYWORDS="TODO:|FIXME:|DevTeam:|XXX:" find "${SRCROOT}" \( -name "*.h" -or -name "*.m" -or -name "*.swift" \) -print0 | xargs -0 egrep --with-filename --line-number --only-matching "($KEYWORDS).*$" | perl -p -e "s/($KEYWORDS)/ warning: $1/"
Original answer was taken from Here
原始答案取自这里
Another alternative is XToDoplugin for Xcode.
另一种选择是Xcode 的XToDo插件。
回答by Leo Cavalcante
You can use XToDo plugin
您可以使用 XToDo 插件
https://github.com/trawor/XToDo
https://github.com/trawor/XToDo
use ctrl+t to trigger the List Window on/off
使用 ctrl+t 触发列表窗口开/关
Easy install with alcatraz use ctrl+t to trigger the List Window on/off
使用 alcatraz 轻松安装,使用 ctrl+t 触发列表窗口开/关
回答by Steve Moser
I started with
我开始了
// TODO: Implement bubble sort
.
// TODO: Implement bubble sort
.
Then I joined a large project and sometimes I needed a todo to live longer than a WIP commit and so to distinguish my todos from my peers I name spaced my todo with my initials:
然后我加入了一个大项目,有时我需要一个待办事项比 WIP 提交活得更久,因此为了将我的待办事项与我的同行区分开来,我用我的首字母命名我的待办事项:
// TODO: SM: Implement bubble sort
// TODO: SM: Implement bubble sort
Sometimes I wanted more visibility so I started to use pragma warnings in some places.
有时我想要更多的可见性,所以我开始在某些地方使用 pragma 警告。
#warning Implement bubble sort
#warning Implement bubble sort
One day I decided to turn on hard mode by adding -Werror
to my cflags. Unfortunately this makes pragma warnings useless because they prevent compilation. And so I went back to using // TODO:
until Jeff Nadeau told me that I can put
有一天,我决定通过添加-Werror
到我的 cflags来打开困难模式。不幸的是,这使得编译指示警告无用,因为它们会阻止编译。所以我又开始使用,// TODO:
直到杰夫纳多告诉我我可以把
-Wno-error=#warnings
-Wno-error=#warnings
in my cflags so as to not treat pragma warnings as errors. So now #warning
and -Werror
can live along side each other.
在我的 cflags 中,以便不将 pragma 警告视为错误。所以,现在#warning
和-Werror
可沿侧对方生活。
回答by nenchev
I tend to write exactly //TODO: Blah blah blah
我倾向于准确地写 //TODO: Blah blah blah
Then I just do a COMMAND-SHIFT-F and look for "//TODO".
然后我只是做一个 COMMAND-SHIFT-F 并寻找“// TODO”。
Using the file outline drop down will only show you TODOs for the current file, but I tend to want to see my project's TODO status.
使用文件大纲下拉菜单只会显示当前文件的 TODO,但我倾向于查看我的项目的 TODO 状态。
Rough solution, but it does it's job.
粗略的解决方案,但它确实有效。
回答by Darren Ehlers
I split up the recognized tokens into Warnings and Errors for my own use, thought I would share it here:
我将识别出的标记分成警告和错误供我自己使用,我想在这里分享一下:
KEYWORDS="STUB:|WARNING:|TODO:|FIXME:|DevTeam:|\?\?\?:"
find "${SRCROOT}" \( -name "*.h" -or -name "*.m" -or -name "*.swift" \) -not -path "${SRCROOT}/Pods/*" -print0 | xargs -0 egrep --with-filename --line-number --only-matching "($KEYWORDS).*$" | perl -p -e "s/($KEYWORDS)/1: warning: $1/"
KEYWORDS="ERROR:|XXX:|\!\!\!:"
find "${SRCROOT}" \( -name "*.h" -or -name "*.m" -or -name "*.swift" \) -not -path "${SRCROOT}/Pods/*" -print0 | xargs -0 egrep --with-filename --line-number --only-matching "($KEYWORDS).*$" | perl -p -e "s/($KEYWORDS)/1: error: $1/"
ERROR_OUTPUT=`find "${SRCROOT}" \( -name "*.h" -or -name "*.m" -or -name "*.swift" \) -not -path "${SRCROOT}/Pods/*" -print0 | xargs -0 egrep --with-filename --line-number --only-matching "($KEYWORDS).*$" | perl -p -e "s/($KEYWORDS)/1: error: $1/"`
exit ${#ERROR_OUTPUT}
回答by Deepraj Chowrasia
#error
and
和
#warning
are also used in C programming
也用于 C 编程
回答by drew..
Another simple method, slightly outside the box, if you don't want to clutter up the methods listing bar, is to use a convention within comments like //Todo:
and when you want to address them en-masse, simply select the Find Navigator, match case and search for //Todo:
另一个简单的方法,稍微超出框,如果你不想弄乱方法列表栏,是在注释中使用约定//Todo:
,当你想集中解决它们时,只需选择查找导航器,匹配大小写并搜索//Todo:
I prefer this as I don't like the methods drop down looking like spagetti-code. And yes, I often have lots of Todo:'s ;)
我更喜欢这个,因为我不喜欢下拉看起来像意大利面条代码的方法。是的,我经常有很多 Todo:'s ;)