Hello, I am Tagore, a beautiful man with beauty and wisdom. Tonight, the big cute fish went out for a party building, drank a little wine and lost consciousness. I’m the only one writing tonight’s article.

It was another stormy day, and the falls were more violent than usual. This situation, I want to recite a poem: “waterfall is like the blue sky white clouds, blue skies, sudden storm, nowhere to escape, always people, unexpected.

On such a stormy day, The big cute fish was writing code and fixing bugs as usual, and everything looked great. That’s when the giant fish spotted a TODO that had been marked earlier:

//TODO: Temporary plan, refactor later
Copy the code

However, more than half a year has passed since the last mark, and our big cute fish has forgotten about the reconstruction. The anxious big cute fish scratches his head and thinks: “This is really embarrassing!” . At this time Tagore just private chat to spell xi Xi waterfall, so big meng fish just told Tagore confused.

In general, when we write code, sometimes we need to mark things that need to be done, things that need to be fixed, things that we don’t have time to fix right now, so we need to mark them up so that we can look at them later.

Xcode also gives us three handy easy tags, MARK, TODO, and FIXME, which are now available in Objective-C or Swift environments. Note that MARK, TODO, and FIXME must all be capitated. Xcode will look for such comments in the code and then display the name in the navigation bar as a bold tag, just as we would use the “#pragma MARK -” symbol to MARK code sections.

MARK, TODO, FIXME:

//TODO: MARK something that needs to be done in the future //MARK something that needs to be fixed or improved in the futureCopy the code

The effect is as follows:

There are also the following tags that Xcode supports:

/ /??? : place of doubt ///!! : Points needing attentionCopy the code

However, having a bold tag is not enough, and without a hint from ⚠️ or ❌, it’s easy to forget the previous tag, just like our cute fish.

How do you add custom flags and display them in warning or error at compile time? The answer is to add a shell script to the Run Script Build Phases:

  1. Switch to thetarget-->build phases-->editor-->add run script build phases

  1. Paste the following code into the shell box
TAGS="TODO:|FIXME:|WARNING:"
ERRORTAG="ERROR:"
find "${SRCROOT}" \( -name "*.h" -or -name "*.m" -or -name "*.swift" \) -print0 | xargs -0 egrep --with-filename --line-number --only-matching "($TAGS).*\$|($ERRORTAG).*\$" | perl -p -e "s/($TAGS)/ warning: \$1/"| perl -p -e "s/($ERRORTAG)/ error: \$1/"
Copy the code

After the shell script is set and the code is compiled, WARNING, TODO, and FIXME will appear as ⚠️, and ERROR will be treated as ❌.

Some people might ask, why not just use #warning? That’s a matter of opinion. If you look closely at the differences in the picture below, you can see why.

In addition, for some developers, there is no tolerance for ⚠️ during team development, and the frequent use of #warning can be a pain in the heart