开发者

What source comments does Xcode recognize as tags?

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:

What source comments does Xcode recognize as tags?

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: -
// MARK: Future Improvements:
// TODO: Make something better
// TODO: Fix some bug

And Xcode will render it out like this:

What source comments does Xcode recognize as tags?

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


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

// 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:

{
    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 BBEdit text editor and its freeware sibling TextWrangler.


Looks like

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

all get translated into #pramga-like markers.

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


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

// MARK: UICollectionViewDataSourcePrefetching

    /// - Tag: Prefetching
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜