Xcode 将哪些源注释识别为标签?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7600435/
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 22:03:22  来源:igfitidea点击:

What source comments does Xcode recognize as tags?

xcodecomments

提问by Matt Wilding

This is mostly for curiosity's sake. I've known for awhile that Xcode is capable of recognizing comments in the form of // TODO: Something I don't feel like doing now. Adding that line to the source of a file will cause that TODO comment to show up in Xcode's navigation bar:

这主要是出于好奇。我早就知道 Xcode 能够识别// TODO: Something I don't feel like doing now. 将该行添加到文件的源代码将导致该 TODO 注释显示在 Xcode 的导航栏中:

enter image description here

在此处输入图片说明

I also recently discovered that comments of the form // MARK: Somethingcan achieve the same effect as #pragma marking something. So I can write a comment that looks like:

最近我也发现表单的评论// MARK: Something可以达到和#pragma marking一样的效果。所以我可以写一个看起来像这样的评论:

// MARK: -
// MARK: Future Improvements:
// TODO: Make something better
// TODO: Fix some bug

And Xcode will render it out like this:

Xcode 会像这样渲染它:

enter image description here

在此处输入图片说明

Which leads me to wonder: Are there other kinds of comments that Xcode can understand to improve project navigation?

这让我想知道:Xcode 是否可以理解其他类型的注释来改进项目导航?

采纳答案by Paul R

There is also MARK, FIXME, !!!and ???, e.g.

还有MARK, FIXME,!!!???, 例如

// FIXME: this bug needs to be fixed

and

// ???: WTF ???

You can see where these are defined in /Applications/Xcode.app/Contents/OtherFrameworks/XcodeEdit.framework/Versions/A/Resources/BaseSupport.xclangspec(or /Developer/Library/PrivateFrameworks/XcodeEdit.framework/Resources/BaseSupport.xclangspecfor older versions of Xcode). Presumably you could also add your own tags here if you wanted to but I have not actually tried this. Here is the relevant section in BaseSupport.xclangspec:

您可以看到这些定义在/Applications/Xcode.app/Contents/OtherFrameworks/XcodeEdit.framework/Versions/A/Resources/BaseSupport.xclangspec(或/Developer/Library/PrivateFrameworks/XcodeEdit.framework/Resources/BaseSupport.xclangspec旧版本的 Xcode)中的位置。据推测,如果您愿意,您也可以在此处添加自己的标签,但我实际上还没有尝试过。这是中的相关部分BaseSupport.xclangspec

{
    Identifier = "xcode.lang.comment.mark";
    Syntax = {
        StartChars = "MTF!?";
        Match = (
            "^MARK:[ \t]+\(.*\)$",
            "^\(TODO:[ \t]+.*\)$",       // include "TODO: " in the markers list
            "^\(FIXME:[ \t]+.*\)$",      // include "FIXME: " in the markers list
            "^\(!!!:.*\)$",              // include "!!!:" in the markers list
            "^\(\?\?\?:.*\)$"         // include "???:" in the markers list
        );
        // This is the order of captures. All of the match strings above need the same order.
        CaptureTypes = (
            "xcode.syntax.mark"
        );
        Type = "xcode.syntax.comment";
    };
},

These tags are also supported in the BBEdittext editor and its freeware sibling TextWrangler.

BBEdit文本编辑器及其免费软件同级TextWrangler也支持这些标签。

回答by Patrick Perini

Looks like

好像

// MARK:
// TODO:
// FIXME:
// ???:
// !!!:

all get translated into #pramga-like markers.

所有都被翻译成#pramga-like 标记。

It appears that they stand for

看来他们代表

// Mark, as in pragma
// To Do note
// Known bug marker
// Serious question about form, content, or function
// Serious concern about form, content, or function

回答by zdravko zdravkin

You can use // MARK: - with tags below as per Apple example

您可以使用 // MARK: - 根据 Apple 示例使用下面的标签

// MARK: UICollectionViewDataSourcePrefetching

    /// - Tag: Prefetching