简体   繁体   English

如何在 Xcode 中标记“待办事项”注释?

[英]How can I mark “To Do” comments in Xcode?

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 。

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 :还有很多选项,例如

  1. // FIXME: Midhun

  2. // ???: Midhun

  3. // !!!: Midhun

  4. // MARK: Midhun
// TODO: the thing todo

是您显示待办事项的方式。

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.当您构建应用程序时,您会收到一个编译器警告(一个黄色三角形,而不是编译器错误),这更像是在提醒您需要做的事情。

With the script below your can see all required tags like warnings.使用下面的脚本,您可以看到所有必需的标签,如警告。

  1. Select your project in the Project Navigator在项目导航器中选择您的项目
  2. Open the target in the sidebar and move to the "Build Phases" tab在侧边栏中打开目标并移动到“构建阶段”选项卡
  3. Click on "+" sign点击“+”号
  4. Select "New Run Script Build Phase"选择“新建运行脚本构建阶段”添加脚本
  5. 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/"

在此处输入图片说明

Original answer was taken from Here原始答案取自这里

Another alternative is XToDo plugin for Xcode.另一种选择是 Xcode 的XToDo插件。

You can use XToDo plugin您可以使用 XToDo 插件

https://github.com/trawor/XToDo https://github.com/trawor/XToDo

使用 ctrl+t 触发列表窗口开/关

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 触发列表窗口开/关

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

Sometimes I wanted more visibility so I started to use pragma warnings in some places.有时我想要更多的可见性,所以我开始在某些地方使用 pragma 警告。

#warning Implement bubble sort

One day I decided to turn on hard mode by adding -Werror to my cflags.有一天,我决定通过将-Werror添加到我的 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所以我又回到使用// TODO:直到 Jeff Nadeau 告诉我我可以把

-Wno-error=#warnings

in my cflags so as to not treat pragma warnings as errors.在我的 cflags 中,以便不将 pragma 警告视为错误。 So now #warning and -Werror can live along side each other.所以现在#warning-Werror可以-Werror

I tend to write exactly:我倾向于准确地写:

//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.粗略的解决方案,但它确实有效。

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}

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:并且当你想集中解决它们时,只需选择 Find导航器,匹配大小写并搜索//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 ;)

#error

and

#warning

are also used in C programming也用于 C 编程

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM