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
What source comments does Xcode recognize as tags?
提问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 的导航栏中:
I also recently discovered that comments of the form // MARK: Something
can achieve the same effect as #pragma mark
ing something. So I can write a comment that looks like:
最近我也发现表单的评论// MARK: Something
可以达到和#pragma mark
ing一样的效果。所以我可以写一个看起来像这样的评论:
// MARK: -
// MARK: Future Improvements:
// TODO: Make something better
// TODO: Fix some bug
And Xcode will render it out like this:
Xcode 会像这样渲染它:
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.xclangspec
for 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