In project development, it is impossible for us to write all the code as needed. During the development process, you must have encountered such problems as demand changes, business logic communication, and runtime environment switching. When a project is large, if a uniform code specification is formed, it will cause a lot of trouble during the project handover and communication between developers.
# Pragma mark-
This tag is most used in iOS development. In fact, the most important thing is to mark, of course, there is also a comment in it. Of course, we can also use //,/**/and other common annotations to describe. However, # pragma mark can be used to display the functions of the entire file in a similar group. Click the list next to the file in the xcode navigation bar to display the following page:
In this way, when other developers view this file, they can clearly see the entire function distribution and the functions related to each function. If you click the tag, you can directly jump to the tag location, which is very convenient. It is time-saving and labor-saving for Business Communication and calling. # Pragma mark-Another advantage is that we often implement delegate, datasource, protocol, and other classes during development. If we # pragma mark-uitableviewdelegate, when we click uitableviewdelegate with the mouse over the command, it will jump directly to the place defined by the delegate, and you can easily view the relevant methods. My personal understanding of the role of # pragma mark is to facilitate interaction between developers. Especially for large projects of many people, if you use # pragma mark as your preferences, it is very catastrophic for project development and maintenance. Not only do developers not know the structure of their entire file, but it will be very big when other developers take over the development. Because objc functions are colloquial in naming, functions can be implemented as soon as they are called. Therefore, in normal development, only some key notes are written, such as the description of the bool variable, business processing logic. Combined with # pragma mark-this can be easily understood by other developers.
# Waring
We recommend that you use this feature. xcode supports displaying the # Waring mark as a compilation warning by default. In software development, you will use special annotations such as todo, fixme, and XXX. These keywords are also supported by many ides. If you add # warning to the code, you need to modify by James. In the xcode compilation warning window, you can see:
During development, we have forced programmers to constantly interrupt their thinking and switch back and forth. For example, the business logic is not fixed, network request address switching, writing dead code for local testing, project joint debugging, and other operations. In the worst case, when the project went online, it suddenly found that the request address was incorrect. When the local device contained dead test data or the Code of other project modules was required, the code of others was changed temporarily, but I have to change it back. This is a major project accident. One or two uncertain changes may be hard for programmers to remember, but when there is more, 1% will be missed. Therefore, the best way to do this is to place a warning on your uncertain business or test data. Start with # Waring and write down the reason, mark the person, time and other instructions. In this way, after the project development is complete, there will be a dedicated time to eliminate these warnings to ensure that there are no omissions.
For developers who still like todo, fixme, and XXX, you can set "build phases" of the project, add new run script build phase, and add the following code.
KEYWORDS="TODO:|FIXME:|XXX:"find "${SRCROOT}" \( -name "*.h" -or -name "*.m" \) -print0 | xargs -0 egrep --with-filename --line-number --only-matching "($KEYWORDS).*\$" | perl -p -e "s/($KEYWORDS)/ warning: \$1/"
In this way, xocde can display these special tags in the form of # Waring.
Use # Waring, # pragma mark